Add support for webpack.config.mjs

Do you want to request a feature or report a bug?
Feature.

What is the current behavior?
Fails with the following exception. I didn’t get a chance to debug into it. Does this live here or webpack-cli?

🐻 $ node --experimental-modules ./node_modules/.bin/webpack --config webpack.config.mjs 
(node:39555) ExperimentalWarning: The ESM module loader is experimental.
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/junger/dev/bugrepro/webpack.config.mjs
    at Object.Module._extensions..mjs (module.js:694:11)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (/Users/junger/dev/bugrepro/node_modules/v8-compile-cache/v8-compile-cache.js:159:20)
    at WEBPACK_OPTIONS (/Users/junger/dev/bugrepro/node_modules/webpack-cli/bin/convert-argv.js:133:13)
    at requireConfig (/Users/junger/dev/bugrepro/node_modules/webpack-cli/bin/convert-argv.js:135:6)
    at /Users/junger/dev/bugrepro/node_modules/webpack-cli/bin/convert-argv.js:142:17
    at Array.forEach (<anonymous>)
    at module.exports (/Users/junger/dev/bugrepro/node_modules/webpack-cli/bin/convert-argv.js:140:15)
    at yargs.parse (/Users/junger/dev/bugrepro/node_modules/webpack-cli/bin/webpack.js:239:39)
    at Object.parse (/Users/junger/dev/bugrepro/node_modules/yargs/yargs.js:543:18)
    at /Users/junger/dev/bugrepro/node_modules/webpack-cli/bin/webpack.js:217:8
    at Object.<anonymous> (/Users/junger/dev/bugrepro/node_modules/webpack-cli/bin/webpack.js:512:3)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/junger/dev/bugrepro/node_modules/webpack/bin/webpack.js:12:2)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at createDynamicModule (internal/loader/ModuleRequest.js:52:15)
    at setExecutor (internal/loader/ModuleWrap.js:49:23)

If the current behavior is a bug, please provide the steps to reproduce.

  1. Create webpack.config.mjs to learn about the new node experimental modules.
  2. Run node --experimental-modules ./node_modules/.bin./webpack --config webpack.config.mjs

What is the expected behavior?
Works.

If this is a feature request, what is motivation or use case for changing the behavior?

~/dev/bugrepro
🐨 $ node --version
v9.5.0
~/dev/bugrepro
🐭 $ ./node_modules/.bin/webpack --version
4.1.1
~/dev/bugrepro

Author: Fantashit

1 thought on “Add support for webpack.config.mjs

Comments are closed.