我对heroku完全陌生,并从Brad Tersey的Udemy课程的视频中逐步建立了我的heroku帐户。我在下课后也已经构建了heroku部署... heroku的构建过程已经工作了一段时间...但是现在它似乎已经坏了,我很难找出原因。
我还应该注意,这可以在我的家用计算机上正常工作...我可以先安装npm,然后再运行npm dev和所有内容加载并运行。
首先,我运行以下命令:
heroku git:remote -a guarded-brook-39446
然后我运行以下命令:
git push heroku master
这是构建日志:
D:\Code\Udemy\MERN\MERN>git push heroku master
Enumerating objects: 809, done.
Counting objects: 100% (809/809), done.
Delta compression using up to 4 threads.
Compressing objects: 100% (685/685), done.
Writing objects: 100% (765/765), 165.50 KiB | 1.38 MiB/s, done.
Total 765 (delta 566), reused 102 (delta 79)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote: NPM_CONFIG_LOGLEVEL=error
remote: NODE_ENV=production
remote: NODE_MODULES_CACHE=false
remote: NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): 8.11.4
remote: engines.npm (package.json): 5.6.0
remote:
remote: Resolving node version 8.11.4...
remote: Downloading and installing node 8.11.4...
remote: npm 5.6.0 already installed with node
remote:
remote: -----> Restoring cache
remote: Caching has been disabled because NODE_MODULES_CACHE=false
remote:
remote: -----> Building dependencies
remote: Installing node modules (package.json + package-lock)
remote:
remote: > nodemon@1.18.9 postinstall /tmp/build_f19e608b09c6e8b101acf02b50e8189b/node_modules/nodemon
remote: > node bin/postinstall || exit 0
remote:
remote: Love nodemon? You can now support the project via the open collective:
remote: > https://opencollective.com/nodemon/donate
remote:
remote: added 372 packages in 10.391s
remote: Running heroku-postbuild
remote:
remote: > mern@1.0.0 heroku-postbuild /tmp/build_f19e608b09c6e8b101acf02b50e8189b
remote: > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:
remote: added 1941 packages in 41.504s
remote:
remote: > client@0.1.0 build /tmp/build_f19e608b09c6e8b101acf02b50e8189b/client
remote: > react-scripts build
remote:
remote: Creating an optimized production build...
remote: Failed to compile.
remote:
remote: Failed to minify the bundle. Error: static/js/main.9856cdb3.chunk.js from Terser
remote: TypeError: Cannot read property 'minify' of undefined
remote: at compiler.run (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/react-scripts/scripts/build.js:169:23)
remote: at finalCallback (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/webpack/lib/Compiler.js:210:39)
remote: at hooks.done.callAsync.err (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/webpack/lib/Compiler.js:226:13)
remote: at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
remote: at AsyncSeriesHook.lazyCompileHook (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/tapable/lib/Hook.js:154:20)
remote: at onCompiled (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/webpack/lib/Compiler.js:224:21)
remote: at hooks.afterCompile.callAsync.err (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/webpack/lib/Compiler.js:553:14)
remote: at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
remote: at AsyncSeriesHook.lazyCompileHook (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/tapable/lib/Hook.js:154:20)
remote: at compilation.seal.err (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/webpack/lib/Compiler.js:550:30)
remote: at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
remote: at AsyncSeriesHook.lazyCompileHook (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/tapable/lib/Hook.js:154:20)
remote: at hooks.optimizeAssets.callAsync.err (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/webpack/lib/Compilation.js:1295:35)
remote: at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
remote: at AsyncSeriesHook.lazyCompileHook (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/tapable/lib/Hook.js:154:20)
remote: at hooks.optimizeChunkAssets.callAsync.err (/tmp/build_f19e608b09c6e8b101acf02b50e8189b/client/node_modules/webpack/lib/Compilation.js:1286:32)
remote: Read more here: http: // bit.ly / CRA-build-minify
remote:
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! client@0.1.0 build: `react-scripts build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the client@0.1.0 build script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.dkOHV/_logs/2019-02-10T01_09_07_572Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! mern@1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm
run build --prefix client`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the mern@1.0.0 heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR! /tmp/npmcache.dkOHV/_logs/2019-02-10T01_09_07_587Z-debug.log
remote:
remote: -----> Build failed
remote:
remote: We're sorry this build is failing! You can troubleshoot common issues here:
remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote: If you're stuck, please submit a ticket so we can help:
remote: https://help.heroku.com/
remote:
remote: Love,
remote: Heroku
remote:
remote: ! Push rejected, failed to compile Node.js app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to guarded-brook-39446.
remote:
To https://git.heroku.com/guarded-brook-39446.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/guarded-brook-39446.git'
我的项目由一个服务器和一个客户端组成。
这是服务器package.json文件:
{
"name": "mern",
"version": "1.0.0",
"description": "social network for developers",
"main": "server.js",
"engines": {
"node": "8.11.4",
"npm": "5.6.0"
},
"scripts": {
"client-install": "npm install --prefix client",
"start": "node server.js",
"server": "nodemon server.js",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"author": "Me",
"license": "MIT",
"dependencies": {
"bcryptjs": "^2.4.3",
"body-parser": "^1.18.2",
"concurrently": "^4.1.0",
"dotenv": "^6.2.0",
"express": "^4.16.3",
"gravatar-url": "^2.0.0",
"jsonwebtoken": "^8.2.0",
"mongoose": "^5.0.12",
"nodemailer": "^4.7.0",
"passport": "^0.4.0",
"passport-jwt": "^4.0.0",
"randomstring": "^1.1.5",
"validator": "^9.4.1"
},
"devDependencies": {
"nodemon": "^1.18.6"
}
}
这是我的客户端package.json文件:
{
"name": "client",
"version": "0.1.0",
"private": true,
"engines": {
"node": "8.11.4",
"npm": "5.6.0"
},
"dependencies": {
"axios": "^0.18.0",
"classnames": "^2.2.5",
"jsonwebtoken": "^8.4.0",
"moment": "^2.22.0",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-image-mapper": "0.0.9",
"react-moment": "^0.8.4",
"react-redux": "^5.0.7",
"react-router-dom": "^4.2.2",
"react-scripts": "^2.1.1",
"reactstrap": "^7.1.0",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"proxy": "http://localhost:5000",
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
答案 0 :(得分:0)
所以我对互联网进行了一些搜索,发现了这篇文章:
https://github.com/facebook/create-react-app/issues/6334,其中erwanriou发表了以下评论:
ok i fix how to do it. We have to change the script just for this case:
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm install terser@3.14.1 --prefix client && npm run build --prefix client"
所以我将我的heroku-postbuild更改为他的建议,并且构建成功!
感谢 erwanriou