question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Making sourcetype unambiguous to support commonjs in addition

See original GitHub issue

Hi,

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:open
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
KeKs0rcommented, Nov 12, 2019

I found a workaround by creating a .babelrc:

{
  "sourceType": "unambiguous"
}

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.

0reactions
Zambonillicommented, Dec 21, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found