Making sourcetype unambiguous to support commonjs in addition
See original GitHub issueHi,
I understand that the configuration is mainly setup to support es6 module syntax. I think it would be great to additionally not break working commonjs.
Webpack itself supports it to a certain degree: You can mix require and export. You can’t mix import and module.exports. https://github.com/webpack/webpack/issues/4039#issuecomment-273804003
The problem is that babel-transform is transforming require statements to imports: https://stackoverflow.com/a/56283408/1602476
This could be prevented (see stackoverflow answer) by setting:
"sourceType": "unambiguous"
Would this be something that could potentially be supported? Since I think it would not break existing setups, but would also allow commonjs to be supported additionally.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How can I use Node.js CommonJS modules in ES6 import ...
The reason I need this is I have a config file written using Node's module.exports syntax that needs to be imported within a...
Read more >How can I use Node.js CommonJS modules in ES6 import ...
And after poking round and looking up this error, I found this answer on another Stack Overflow which helped me fix it by...
Read more >Modules: Packages | Node.js v19.3.0 Documentation
However, now that Node.js supports both CommonJS and ES modules, ... In addition to the "exports" field, there is a package "imports" field...
Read more >Migrating Webpack from v1 to v5 - Ahmet Ömer
... adding "sourceType": "unambiguous" to the Babel configuration. ... In the root of your project, create webpack.config.common.js .
Read more >Options - Babel.js
would allow plugins and presets to decide that, since ES modules are supported, they will skip compilation of ES modules into CommonJS modules....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I found a workaround by creating a
.babelrc
:and its picked up by babel-transform, which resolves the issue. I think this can be closed and potntially just documented, that .babelrc can be used with this plugin.
For anyone else hitting this, you can manually update your version of serverless-bundle and add sourceType: “unambiguous” to the babel-loader config here.
https://github.com/AnomalyInnovations/serverless-bundle/blob/master/src/webpack.config.js#L157