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.

ESM Format modules are not transpiled to ES5.

See original GitHub issue

Describe the bug I am currently encountering the following error when I try import the code into older code base that has ejected create-react-app:

/Users/djohnston/git/project/node_modules/@monaco-editor/react/lib/es/Editor/Editor.js
Module parse failed: Unexpected token (105:6)
You may need an appropriate loader to handle this file type.
|       model: defaultModel,
|       automaticLayout: true,
|       ...options
|     }, overrideServices);
|     saveViewState && editorRef.current.restoreViewState(viewStates.get(autoCreatedModelPath));

The issue appears to be that it doesn’t like the …spread syntax.

To Reproduce

https://github.com/dwjohnston/cra1-monaco

Expected behavior

Of all of the imports this project has been using, this is the first time this error has been encountered - which suggests that every other dependency we use transpiles down to ES5.

Is it reasonable to ask you to transpile the ESM module to ES5?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
dwjohnstoncommented, Apr 12, 2021

Alright, here’s the workaround if you are using ejected CRA at react scripts 1.1.5

Add this to your webpack configs:

          {
            test: /\.m?js$/,
            exclude: {
              test: /(node_modules)/, // Exclude libraries in node_modules ...
              not: [

                /@monaco-editor\/react/
              ]
            },
            use: {
              loader: require.resolve('babel-loader'),
              options: {
                babelrc: false, 

                "plugins": [
                  [require.resolve("babel-plugin-transform-object-rest-spread"), { "useBuiltIns": true }]]
                
              }
            }
          },

I do still think that you should accept the PR/transpile the spread operators though.

0reactions
dwjohnstoncommented, Apr 12, 2021

FYI I’ve posted this question on Stack Overflow re: odd babel behaviour when trying to transpile your package from my end: https://stackoverflow.com/questions/67051317/babel-is-examining-the-package-json-of-a-target-module-for-configuration-when-tr

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to transpile ES modules with webpack and Node.js
Learn how webpack interacts with and supports ES modules in this deep dive tutorial on transpilation in Node.js.
Read more >
In Rollup, create ESM module with no babel transpiling except ...
1 Answer 1 · Remove the .babelrc file · Move its configuration to rollup.config.js · Configure rollup-esm.config.js to explicitly handle class ...
Read more >
babel/plugin-transform-modules-umd
This plugin transforms ES2015 modules to UMD. Note that only the syntax of import/export statements ( import "./mod.js" ) is transformed, as Babel...
Read more >
rollup.js
Importing CommonJS · Publishing ES Modules ... file (see example) --no-esModule Do not add __esModule property --exports <mode> Specify export mode (auto, ...
Read more >
How to Build and Publish ES6 Modules Today, with Babel and ...
js 6 but additionally make sure that the import/export statements in the original source code are not transpiled into ES5 module.exports syntax. Let...
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