Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running r_js XMLHttpRequest is not defined #51

Open
BenSpace48 opened this issue Feb 21, 2020 · 2 comments
Open

Error when running r_js XMLHttpRequest is not defined #51

BenSpace48 opened this issue Feb 21, 2020 · 2 comments

Comments

@BenSpace48
Copy link

I receive the below error when running:

sudo r_js -o build.json \
    baseUrl=pub/static/frontend/MySite/default/en_GB_src \
    dir=pub/static/frontend/MySite/default/en_GB \
    optimize=none
Tracing dependencies for: requirejs/require
ReferenceError: XMLHttpRequest is not defined
In module tree:
    mage/dataPost
      Magento_Ui/js/modal/confirm
        Magento_Ui/js/modal/modal
          text

Error: ReferenceError: XMLHttpRequest is not defined
In module tree:
    mage/dataPost
      Magento_Ui/js/modal/confirm
        Magento_Ui/js/modal/modal
          text

This appears to be caused by XMLHttpRequest being a Web API and not a Node API.

@shakyShane
Copy link
Contributor

shakyShane commented Feb 21, 2020

It's because the text module that magento provides is not suitable for bundling - I tend to add this

var config = {
    paths: {
        "text": "Acme_Build/js/text"
    },
    shim: {
        "jquery/jquery-migrate": {
            "deps": [
                "jquery",
                "jquery/jquery.cookie"
            ]
        }
    }
};

to fix that, plus another issue with jquery/jquery-migrate as seen.

Then, in Acme_Build module i'd have web/js/text.js with the following https://gist.github.com/shakyShane/19118803bee502b5ab648abae201986d which is just a copy/paste of a version of the 'text' module that actually works 😂

@passtet
Copy link

passtet commented Feb 4, 2021

@BenSpace48 I have managed to fix it using https://community.magento.com/t5/Magento-2-x-PWA-Theming-Layout/Advanced-JavaScript-bundling-quot-ReferenceError-XMLHttpRequest/td-p/108719#

Just change text as suggested above to use a native requirejs/text instead of magento one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants