Answer the question
In order to leave comments, you need to log in
Why don't webpack2 and babel build code with the unwrap operator "..."?
Main file code ./src/index.js
:
let a = { s: 4 }
let b = { ...a };
console.log(b);
const path = require("path");
module.exports = {
entry: "./src/index.js",
output: {
path: path.join(__dirname, "dist"),
filename: "bundle.js"
},
module: {
rules: [{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: "babel-loader"
}]
}
}
{
"name": "webpackreacttest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.25.0",
"babel-loader": "^7.0.0",
"babel-preset-env": "^1.5.2",
"babel-preset-es2015": "^6.24.1",
"webpack": "^2.6.1"
}
}
{
"presets": ["es2015"]
}
npm start
, then an error occurs:D:\projects\nodejs\webpackreacttest>npm start
> [email protected] start D:\projects\nodejs\webpackreacttest
> webpack
Hash: ea52a0a36c328ecb7082
Version: webpack 2.6.1
Time: 612ms
Asset Size Chunks Chunk Names
bundle.js 3.19 kB 0 [emitted] main
[0] ./src/index.js 558 bytes {0} [built] [failed] [1 error]
ERROR in ./src/index.js
Module build failed: SyntaxError: D:/projects/nodejs/webpackreacttest/src/index.js: Unexpected token (2:10)
1 | let a = { s: 4 }
> 2 | let b = { ...a };
| ^
3 | console.log(b);
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] start: `webpack`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\toly1\AppData\Roaming\npm-cache\_logs\2017-06-14T17_53_46_285Z-debug.log
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question