我在部署到Heroku上仍然遇到问题,我无法找出我一生中出了什么问题。 Heroku错误日志在成功构建我的应用程序之后告诉我:
-----> 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
似乎还指示其他内容?在scripts
的package.json
部分中,仅按住start
键并删除其他键。
您在scripts
中的package.json
应该是,
"scripts": {
"start": "node server.js"
},
同样在部署之前,请手动构建react应用。
Heroku弄乱了所有这些build
脚本。
在许多成功的部署之后,我的部署莫名其妙地开始失败之后,就遇到了这个问题。
从缓存node_modules
停止heroku似乎对我有用。
heroku config:set NODE_MODULES_CACHE=false
然后git push heroku master
[在听到Heroku不能很好地处理锁定文件之后,我没有提交package-lock.json
,但是想知道这是否是问题。