Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
109
rated 0 times [  110] [ 1]  / answers: 1 / hits: 7178  / 4 Years ago, sat, july 25, 2020, 12:00:00

I'm building a webpack app and I'm interested in use ESM through the entire app, meaning that build the webpack.config file with ESM imports.


I now this is possible using Babel, but this was before npm added the "type": "module" supporting now ESM imports without babel... I already tried it with Express and it worked but with Webpack I get this:


> ...proyectDirectory/node_modules/webpack-cli/bin/cli.js:93

> require() of ES modules is not supported.

So I was wondering if there is a version of webpack-cli that use import instead of require


More From » npm

 Answers
13

Update to at least webpack-cli 4.5.0. Support for native ESM configuration files has just been added: https://github.com/webpack/webpack-cli/releases/tag/webpack-cli%404.5.0


This means that if you're using webpack.config.js in a directory with {"type": "module"} in its package.json, it will work.


It will also work if you simply name your file webpack.config.mjs


[#3081] Wednesday, July 22, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lucianod

Total Points: 667
Total Questions: 106
Total Answers: 92

Location: Jordan
Member since Thu, Aug 5, 2021
3 Years ago
lucianod questions
;