-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Babel 7 not being executed on webpack.config.babel.js #5960
Description
What is the current behavior?
Executing webpack with a ES6+ config file (webpack.config.babel.js) whilst using Babel 7 leads to a SyntaxError being reported e.g.
$ webpack --env.production
<OMITTED>/webpack.config.babel.js:1
(function (exports, require, module, __filename, __dirname) { import path from 'path'
^^^^^^
SyntaxError: Unexpected token import
If the current behavior is a bug, please provide the steps to reproduce.
-
Install the latest
webpackand the latest@babel/core&@babel/preset-env(e.g 7.0.0-beta.32) -
Create a
webpack.config.babel.jswith ES6+ syntax e.g.echo "import path from 'path'" > webpack.config.babel.jsNote: For illustrative purposes only, this obviously doesn't produce a valid webpack config, but it's sufficient to recreate the issue.
-
Create a
.babelrcwith theenvpreset:echo "{\"presets\":[\"@babel/env\"]}" > ./.babelrc -
Run webpack e.g.
webpack
What is the expected behavior?
Babel to to be executed on webpack.config.babel.js before Node executes the file.
Following the steps above you're expecting a webpack specific error regarding an invalid configuration:
<OMITTED>/node_modules/webpack/bin/convert-argv.js:507
throw new Error("'output.filename' is required, either in config file or as --output-filename");
Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
webpack: 3.8.1
@babel/core: 7.0.0-beta.32
@babel/preset-env: 7.0.0-beta.32
What I'm assuming is happening is that Webpack is looking for the presence of a babel-core package, can't find it, so proceeds without using babel. Babel 7 has scoped packages, the new package is @babel/core.