当我尝试构建我的应用程序时。 npm run build命令每次都会失败。当我使用npm start命令时,一切正常,但无法使用该命令构建应用程序。 这是我的错误:
PS G:\self learning\react js\resort-reactjs> npm run build
> resort@0.1.0 build G:\self learning\react js\resort-reactjs
> react-scripts build
Creating an optimized production build...
Failed to compile.
static/js/main.b4300d14.js from UglifyJs
SyntaxError: Unexpected token: operator (>) [./~/contentful/dist/contentful.node.js:3909,0]
npm ERR! Windows_NT 10.0.18362
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\USER\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v12.18.1
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! resort@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the resort@0.1.0 build script 'react-scripts build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the resort package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! react-scripts build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs resort
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls resort
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! G:\self learning\react js\resort-reactjs\npm-debug.log
在我的package.json文件中,所有内容都已更新。我的package.json文件在这里。 :
{
"name": "resort",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-icons": "^3.10.0",
"react-router-dom": "^5.2.0",
"react-scripts": "0.9.5",
"styled-components": "^5.1.1"
},
"devDependencies": {},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
答案 0 :(得分:0)
package.json文件对我来说很好。我认为这是一个错误,或者至少是一个文献记载不充分的错误。尝试调试或只是清除项目中不需要的不需要的文件,然后重新开始构建。