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 both Meteor and babel compile an ecmascript module #12035

Closed
zodern opened this issue May 13, 2022 · 1 comment · Fixed by meteor/reify#2 · May be fixed by benjamn/reify#369
Closed

Error when both Meteor and babel compile an ecmascript module #12035

zodern opened this issue May 13, 2022 · 1 comment · Fixed by meteor/reify#2 · May be fixed by benjamn/reify#369

Comments

@zodern
Copy link
Collaborator

zodern commented May 13, 2022

Reproduction:

  1. meteor npm install [email protected] and import it on the client import swiper from 'swiper';
  2. In the package.json, have Meteor recompile swiper:
{
    "meteor": {
        "nodeModules": {
            "recompile": {
                "swiper": [
                    "legacy"
                ]
            }
        }
    }
}

When running in a legacy browser, there is the error in the node_modules/swiepr/cjs/components/core/core-class.js, which was bundled as part of the modules.js file.

Assignment to read-only properties is not allowed in strict mode

This is caused by:

  1. The node_modules/swiepr/cjs/components/core/core-class.js file was already compiled by Babel before the package was published. Babel added the line exports.__esModule = true
  2. When Meteor compiles the file, Babel adds an import to a babel runtime helper. This runtime helper is imported using ECMAScript import syntax instead of using require.
  3. The reify compiler runs, changing the import to be a call to module.link

When the file is run in the browser:

  1. module.link is called to import the babel helper. module.link also marks the module as being an ecmascript module, setting exports.__esModule to a read only value
  2. Next, the line babel aded, exports.__esModule = true, runs. This errors since __esModule is read only.
zodern added a commit to zodern/reify that referenced this issue May 25, 2022
Avoids an error if the file was already compiled by babel, and babel adds the line `exports.__esModule = true`.
Fixes meteor/meteor#12035
@zodern
Copy link
Collaborator Author

zodern commented May 25, 2022

I opened benjamn/reify#369 to fix this, and also meteor/reify#2 for our fork of reify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment