我要构建我的项目
我编写了这段代码来构建我的项目npm run build
但是我得到了这个错误:
Hash: 9e32da691bd77c2f4321
Version: webpack 4.6.0
Time: 10303ms
Built at: 2018-07-03 16:31:00
1 asset
Entrypoint main = main.js
[9] ./node_modules/react-router-dom/es/index.js + 30 modules 75.7 KiB {0} [built]
| 31 modules
[40] ./node_modules/react-redux/es/index.js + 23 modules 43 KiB {0} [built]
| 24 modules
[42] ./src/public/appStyle.css 1.1 KiB {0} [built]
[106] ./node_modules/css-loader??ref--5-1!./src/public/bootstrap.min.css 532 KiB {0} [built]
[107] ./src/public/bootstrap.min.css 1.11 KiB {0} [built]
[115] ./src/public/webfonts/fa-regular-400.woff2 182 bytes {0} [built] [failed] [1 error]
[116] ./src/public/webfonts/fa-brands-400.svg 247 bytes {0} [built] [failed] [1 error]
[117] ./src/public/webfonts/fa-brands-400.ttf 182 bytes {0} [built] [failed] [1 error]
[120] ./node_modules/css-loader??ref--5-1!./src/public/css/fontawesome-all.css 198 KiB {0} [built]
[121] ./src/public/css/fontawesome-all.css 1.13 KiB {0} [built]
[123] ./node_modules/css-loader??ref--5-1!./src/public/style.css 60.6 KiB {0} [built]
[124] ./src/public/style.css 1.09 KiB {0} [built]
[129] ./src/reducers/index.js 396 bytes {0} [built]
[131] ./src/store.js 384 bytes {0} [built]
[143] ./src/index.js 815 bytes {0} [built]
+ 130 hidden modules
ERROR in ./src/components/WebApp/Routes/Register/Main.js
Module build failed: SyntaxError: Unexpected token (106:14)
104 | return {
105 | date : {
> 106 | ...prevState.date,
| ^
107 | day : {
108 | 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9, 10: 10, 11: 11, 12: 12, 13: 13, 14: 14, 15: 15, 16: 16, 17: 17, 18: 18, 19: 19, 20: 20, 21: 21, 22: 22, 23: 23, 24: 24, 25: 25, 26: 26, 27: 27, 28: 28, 29: 29, 30: 30
109 | }
@ ./src/components/WebApp/Routes/Register/Register.js 21:12-29
@ ./src/components/App.js
@ ./src/index.js
ERROR in ./src/components/WebApp/Routes/Search/MainCategories.js
Module build failed: SyntaxError: Unexpected token (147:10)
145 | return {
146 | elements : {
> 147 | ...prevState.elements,
| ^
148 | [status] : {
149 | id : id,
150 | name : name
@ ./src/components/WebApp/Routes/Search/SearchCategories.js 17:22-49
@ ./src/components/App.js
@ ./src/index.js
ERROR in ./src/components/OnePage/OnePage.js
Module build failed: SyntaxError: Unexpected token (16:13)
14 |
15 |
> 16 | finishLoad = (isLoad) => {
| ^
17 | this.setState({ isLoad: isLoad })
18 | }
19 |
@ ./src/components/App.js 13:15-43
@ ./src/index.js
ERROR in ./src/components/WebApp/Routes/Support/Main.js
Module build failed: SyntaxError: Unexpected token (4:18)
2 | import send from './../../../../public/img/send.svg'
3 | export default class Main extends Component{
> 4 | continueMessage = () => {
| ^
5 | this.refs.inputBox.focus();
6 | }
7 | render(){
@ ./src/components/WebApp/Routes/Support/Support.js 17:12-29
@ ./src/components/App.js
@ ./src/index.js
ERROR in ./src/public/webfonts/fa-brands-400.svg
Module parse failed: Unexpected token (1:0)
You may need an appropriate loader to handle this file type.
| <?xml version="1.0" standalone="no"?>
| <!--
| Font Awesome Free 5.0.6 by @fontawesome - http://fontawesome.com
@ ./node_modules/css-loader??ref--5-1!./src/public/css/fontawesome-all.css 7:70780-70822
@ ./src/public/css/fontawesome-all.css
@ ./src/index.js
Child html-webpack-plugin for "index.html":
1 asset
Entrypoint undefined = ./index.html
[0] (webpack)/buildin/module.js 497 bytes {0} [built]
[1] (webpack)/buildin/global.js 489 bytes {0} [built]
[3] ./node_modules/html-webpack-plugin/lib/loader.js!./public/index.html 664 bytes {0} [built]
+ 1 hidden module
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! sevenapp@0.1.0 build: `webpack --mode production`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the sevenapp@0.1.0 build 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! /Users/mohammadmehdi/.npm/_logs/2018-07-03T12_01_00_879Z-debug.log
我正在使用npm 6.0.1和webpack 4。
我的Webpack配置为:
const HtmlWebPackPlugin = require("html-webpack-plugin");
const htmlWebpackPlugin = new HtmlWebPackPlugin({
template: "./public/index.html",
filename: "./index.html"
});
module.exports = {
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.css$/,
use: [
{
loader: "style-loader"
},
{
loader: "css-loader",
options: {
modules: true,
importLoaders: 1,
localIdentName: "[name]_[local]_[hash:base64]",
sourceMap: true,
minimize: true
}
}
]
}
]
},
plugins: [htmlWebpackPlugin]
};
我的其余文件在下面。
package.json:
{
"name": "sevenapp",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"bootstrap": "^4.0.0",
"html-webpack-plugin": "^3.2.0",
"jquery": "^3.3.1",
"rc-pagination": "^1.16.4",
"react": "^16.2.0",
"react-countup": "^3.0.3",
"react-dom": "^16.2.0",
"react-paginate": "^5.2.3",
"react-player": "^1.6.4",
"react-popup": "^0.9.3",
"react-redux": "^5.0.7",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-scripts": "1.1.1",
"redux": "^4.0.0"
},
"scripts": {
"start": "webpack-dev-server --mode development --open",
"build": "webpack --mode production",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"description": ":D",
"main": "index.js",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"css-loader": "^0.28.11",
"jshint": "^2.9.5",
"jshint-loader": "^0.8.4",
"style-loader": "^0.21.0",
"webpack": "^4.6.0",
"webpack-cli": "^2.0.15"
},
"author": "MM",
"license": "ISC"
}
.babelrc
{
"presets": [
"env",
"react"
]
}
我怎么了?
我的操作系统是macOS highSierra版本10.13.3 节点js版本10 反应版本16.2
答案 0 :(得分:0)
默认情况下,默认情况下,Babel中没有其余的/扩展运算符(...
),因此您至少需要stage 3 preset(或本身的babel-plugin-transform-object-rest-spread)才能正常工作:
.babelrc
{
"presets": [
"env",
"react",
"stage-3"
]
}