![](/img/trans.png)
[英]Why is devDependencies' pruning skipped even if NPM_CONFIG_PRODUCTION is true?
[英]Heroku Deployment Continues to Fail at "Pruning devDependencies" Step
我繼續在部署到 Heroku 時遇到問題,我無法找出我的生活出了什么問題。 Heroku 錯誤日志在成功構建我的 React 應用程序后告訴我:
-----> Caching build
- node_modules
-----> Pruning devDependencies
npm ERR! Cannot read property 'match' of undefined
這是我的 package.json
{
"name": "test",
"version": "1.0.0",
"homepage": "./",
"description": "test",
"main": "server.js",
"node": "v12.13.1",
"npm": "6.13.7",
"scripts": {
"heroku": "node server.js",
"client-install": "npm install --prefix client",
"build": "cd client && react-scripts build",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
},
"author": "John Doe",
"license": "MIT",
"dependencies": {
"@material-ui/core": "^4.8.0",
"axios": "^0.19.0",
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.3",
"classnames": "^2.2.6",
"concurrently": "^5.1.0",
"date-fns": "^2.8.1",
"debug": "^4.1.1",
"depcheck": "^0.9.1",
"eslint-plugin-flowtype": "^4.6.0",
"express": "^4.16.4",
"fibers": "^4.0.2",
"growl": "^1.10.5",
"heroku": "^7.35.1",
"history": "^4.10.1",
"is-empty": "^1.2.0",
"jquery": "^3.4.1",
"jsonwebtoken": "^8.3.0",
"jwt-decode": "^2.2.0",
"material-table": "^1.54.2",
"material-ui": "^0.20.2",
"minimatch": "^3.0.4",
"moment": "^2.23.0",
"mongodb": "^3.5.3",
"mongoose": "^5.8.9",
"mongoose-global": "^1.0.1",
"morgan": "^1.9.1",
"node-sass": "^4.13.0",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"plaid": "^4.6.0",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-ga": "^2.7.0",
"react-plaid-link-button": "0.0.4",
"react-router-dom": "^5.1.2",
"react-scripts": "^3.3.0",
"react-slick": "^0.25.2",
"react-stripe-elements": "^6.0.1",
"react-vis": "^1.11.7",
"redux-thunk": "^2.3.0",
"sass": "^1.24.0",
"slick": "^1.12.2",
"slick-carousel": "^1.8.1",
"typescript": "^3.7.4",
"update-mongo": "0.0.4",
"validator": "^12.2.0",
"vis": "^4.21.0-EOL"
},
"devDependencies": {},
"engines": {
"node": "12.x"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
也許最令人沮喪的是,前幾天我能夠成功部署一次,但我不確定發生了什么變化。 回顧我的 git,我看不出有什么不同。
我嘗試過的事情:
"devDependencies": {}
到我的 package.json (雖然我沒有它就成功部署了)engines
部分添加到我的 package.json 以匹配。我懷疑可能是問題所在:
npm ERR! Cannot read property 'match' of undefined
npm ERR! Cannot read property 'match' of undefined
似乎表示其他內容?在我的部署在多次成功之后莫名其妙地開始失敗之后,就遇到了這個問題。
從緩存node_modules
停止 heroku 似乎對我node_modules
。
heroku config:set NODE_MODULES_CACHE=false
然后git push heroku master
在聽說 Heroku 與鎖文件相處得不好后,我沒有提交package-lock.json
,但想知道這是否是問題所在。
請rm -rf node_modules && npm i
也一定要跟蹤package-lock.json
文件
只要你在那里,就沒有關系,但添加一個.nvmrc
文件可能是個好主意
node -v >> .nvmrc
讓我們知道它是否有幫助
在package.json
的scripts
部分,只保留start
鍵並刪除其他鍵。
你在package.json
scripts
應該是,
"scripts": {
"start": "node server.js"
},
同樣在部署之前,手動構建 react 應用程序。
Heroku 搞砸了所有這些build
腳本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.