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
plugin-babel _rollupPluginBabelHelpers contains esm content but is interpreted as commonjs #1031
Comments
Thinking about this a bit more, I don't think this is a problem with just plugin-babel. Rollup does not apply the |
Having this issue too! Any solution so far? |
i've opened the pull request rollup/rollup#4270, which should resolve this. |
This release of rollup contains a fix that means babel helpers in the esm build get generated with a .mjs extension, rather than a .js extension. This fixes an error that occures when trying to use the esm build in node. See rollup/plugins#1031
This release of rollup contains a fix that means babel helpers in the esm build get generated with a .mjs extension, rather than a .js extension. This fixes an error that occures when trying to use the esm build in node. See rollup/plugins#1031
…#2082) Update rollup to latest This release of rollup contains a fix that means babel helpers in the esm build get generated with a .mjs extension, rather than a .js extension. This fixes an error that occures when trying to use the esm build in node. See rollup/plugins#1031
@rollup/plugin-babel
Expected Behavior
Running rollup, and then running the output script is successful, it should console log out some content
Actual Behavior
Running rollup and then running the output script throws an error, as it is treating the _rollupPluginBabelHelpers.js file as a commonjs file thanks to the
.js
file extension, however it contains esm content.Additional Information
When using the output options:
output: { format: 'esm', dir: 'output', entryFileNames: '[name][assetExtname].mjs', preserveModules: true}
and authoring source code that requires bundled babel helpers, the helpers are always output to a file called_rollupPluginBabelHelpers.js
. This file is problematic as it contains esm code, but has a .js extension, and as there is no "type:module" in a package.json, node attempts to interpret this file as commonjs. Thus when you try to runnode output/index.mjs
it errors when trying to import the helper file as there is a mismatch (expected cjs but got esm).This could be fixed by adding a "type:module" to the package.json to manipulate what type of content node expects when it sees a js file but in my real-world need for this I'm creating two builds - one with cjs content, and one mjs content and I'd like my cjs content to continue to use the
.js
file extension, while mjs content uses.mjs
.I believe plugin-babel needs a mechanism to control the output filename of the helpers file, instead of always outputting a
.js
file.I'm not sure if there's any way that it can pick up the naming convention used by
output.entryFileNames
(and thus if myentryFileNames
ends in a .mjs then I get a_rollupPluginBabelHelpers.mjs
file). If not perhaps this could be solved by adding additionalbabelHelpers
option called "bundledMjs" that outputs mjs files, or some other mechanism for controling the extension.The text was updated successfully, but these errors were encountered: