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.

Error: ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: 581

See original GitHub issue

Bug Report

Error: ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: 581

Current behavior

Error: ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: 581

Expected behavior There is no abnormal

Environment

webpack version: “webpack”: “^5.13.0”, Node.js version: v10.15.3 Operating System: mac Additional tools:vscode “@babel/core”: “^7.12.10”, “@babel/preset-env”: “^7.12.11”,

Possible Solution

Additional context babel.config.js:

module.exports = {
  presets: [
    [
      '@babel/preset-env',
      {
        corejs: 2,
        useBuiltIns: 'usage'
      }
    ],
    '@vue/babel-preset-jsx'
  ],
  plugins: []

}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

15reactions
nicolo-ribaudocommented, Feb 16, 2021

@Mikilll94 Adding sourceType: "unambiguous" to babel.config.js seems to fix the error.

"umabiguous" tells Babel to automatically detect if it’s transforming a CJS or ESM file, so that it doesn’t inject import statements in CJS dependencies.

Then there is another error (process is not defined), but it seems unrelated.

7reactions
wfabiocommented, Apr 14, 2021

Adding "sourceType": "unambiguous" to my babel.config.json fixed the issue

babel.config.json

{
 "sourceType": "unambiguous",
 "plugins": ["@babel/plugin-transform-runtime"],
 "presets": ["@babel/preset-env"]
}

webpack.config.js

{
       test: /\.js$/,
       exclude: /(node_modules|bower_components)/,
       use: {
         loader: 'babel-loader',
         options: {
           presets: ['@babel/preset-env'],
           plugins: ['@babel/plugin-transform-runtime']
         }
       }
     }

Thank you so much!

Read more comments on GitHub >

github_iconTop Results From Across the Web

ES Modules may not assign module.exports or exports.*, Use ...
I get this error when I try to export a function with module.exports and when I import it inside another file. I tried...
Read more >
module.exports and ES modules (ESM) import export in Node.js
The syntax would change a little bit as we cannot assign object and access its elements as we would do directly with module.exports,...
Read more >
Error when trying to implement laravel translation into vuejs file
Error : ES Modules may not assign module.exports or exports ; export syntax, instead: ./resources/app/translation.js at Object ; as exports] (app.js:417882) ...
Read more >
Changelog - esbuild - Breword 文档集合
esm -file.js var esm_file_exports = {}; __export(esm_file_exports, ... syntax and uses browser-style import order that other languages might not be expecting ...
Read more >
import - JavaScript - MDN Web Docs - Mozilla
To load modules in non-module contexts, use the dynamic import syntax ... exporting it may mutate it and the imported value would change....
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