Using ES version of library (node_module) is not working
See original GitHub issueDescribe the bug
Webpack throws an error when I change my code to use “es” version of libraries
Environment
Steps to reproduce
- Add
@material-ui/core
to your project - Use any “es” variant of the code from that library. This particular code uses optional chaining in es version of the code
import TextField from "@material-ui/core/es/TextField";
- Webpack dev
yarn start
or Webpack buildyarn build
both fails with the following error
The fix
- So after digging throught the issue, I have found out that this is happening due to Optional Chaining and Nullish Coalescing not supported in the JS parser
acorn v6.x.x
which is what Webpack 4 uses. Issue details here - And on my computer, I edited the webpack config in node_modules and added the two presets to the last module
rules
which processes JS outside ofsrc
. - This has fixed the issue
If this usecase is generic enough, Can I raise a pull request to make these changes??
If not, I can use something like react-app-rewired
to edit it for our usecase. Also this change will be temporary until we move to Webpack 5.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:5 (1 by maintainers)
Top Results From Across the Web
was compiled against a different Node.js version using ...
Turns out my problem was user-error: make sure the version of node you are using for running is the same that you are...
Read more >Node Modules at War: Why CommonJS and ES ... - Code Red
I'll conclude with three guidelines for library authors to follow: Provide a CJS version of your library; Provide a thin ESM wrapper for...
Read more >How To Use Node.js Modules with npm and package.json
Since the default value for name will work for this tutorial, press ENTER to accept it. The next value to enter is version...
Read more >Using ES modules in Node.js - LogRocket Blog
Learn about the state of ES modules in Node today, including concerns realted to transitioning from and interoperability with CommonJS.
Read more >Documentation - ECMAScript Modules in Node.js - TypeScript
For the last few years, Node.js has been working to support running ECMAScript ... as ES modules or CommonJS modules, and defaults to...
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
This is fixed in Create React App v5 for the modules I was having issues with.
@Malvineous actually Babel is run for node module code as well with
preset-env
which uses browser list to transpile, I’d say the support is good for library code too. But acorn issue is preventing us from using Optional chaining & Nullish coalescing from library code.