React npm run build 每次都失败
Posted
技术标签:
【中文标题】React npm run build 每次都失败【英文标题】:React npm run build is getting failed every time 【发布时间】:2020-11-28 13:07:58 【问题描述】:当我尝试构建我的 React 应用程序时。 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"
【问题讨论】:
这可能会回答您的问题***.com/a/46954832/10028748 你在代码库的其他地方有意外的运算符'>',在开发模式下运行并检查 如何找到意外的运算符?运行代码时在哪里没有显示错误或警告! @bews99 SyntaxError: Unexpected token: operator (>) [./~/contentful/dist/contentful.node.js:3909,0] is the error my contentful.node.js 3909 number line: module .exports = (flag, argv) => @bews99 【参考方案1】:package.json 文件对我来说看起来不错。我认为这是一个错误,或者至少是一个记录不充分的错误。尝试调试或只清理项目周围不需要的不需要的文件,然后重新启动构建。
【讨论】:
以上是关于React npm run build 每次都失败的主要内容,如果未能解决你的问题,请参考以下文章
npm run build在bitbucket管道中失败,因为它无法解析某些文件
Create-react-app npm run build 太慢了
create-react-app 中的“npm run build”是啥?
为啥“npm run build”会产生错误“react-scripts Permission denied”?