问题
Side note: I've used this same method for deployment about 3 times and now all of the sudden it's not working... Makes me think that something just updated with heroku??? IDK
Trying to push my MERN Stack application to heroku but I'm getting an error, here is my package.json file:
{
"name": "jordanwebsite",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"start": "node server.js",
"server": "nodemon server.js",
"test": "echo \"Error: no test specified\" && exit 1",
"client-install": "npm install --prefix client",
"client": "npm start --prefix client",
"dev": "concurrently \"npm run server\" \"npm run\tclient\"",
"heroku-postbuild": "cd client && NPM_CONFIG_PRODUCTION=false npm install && npm run build"
},
"author": "Jordan Harris",
"license": "ISC",
"dependencies": {
"axios": "^0.18.0",
"body-parser": "^1.18.3",
"concurrently": "^4.1.0",
"express": "^4.16.4",
"nodemon": "^1.18.9"
}
}
Here are the logs:
$ git push heroku master
Enumerating objects: 40, done.
Counting objects: 100% (40/40), done.
Delta compression using up to 8 threads
Compressing objects: 100% (38/38), done.
Writing objects: 100% (40/40), 2.39 MiB | 637.00 KiB/s, done.
Total 40 (delta 0), reused 0 (delta 0)
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=true
remote: NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote: engines.node (package.json): unspecified
remote: engines.npm (package.json): unspecified (use default)
remote:
remote: Resolving node version 10.x...
remote: Downloading and installing node 10.15.1...
remote: Using default npm version: 6.4.1
remote:
remote: -----> Building dependencies
remote: Installing node modules (package.json)
remote:
remote: > nodemon@1.18.9 postinstall /tmp/build_1c67c2822e7364298c69e79a4318103a/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 340 packages from 197 contributors and audited 2497 packages in
10.466s
remote: found 0 vulnerabilities
remote:
remote: Running heroku-postbuild
remote:
remote: > jordanwebsite@1.0.0 heroku-postbuild /tmp/build_1c67c2822e7364298c69e79a4318103a
remote: > cd client && NPM_CONFIG_PRODUCTION=false npm install && npm run build
remote:
remote: added 1963 packages from 688 contributors and audited 35917 packages in 45.094s
remote: found 0 vulnerabilities
remote:
remote:
remote: > client@0.1.0 build /tmp/build_1c67c2822e7364298c69e79a4318103a/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.4d56311f.chunk.js from Terser
remote: TypeError: Cannot read property 'minify' of undefined
remote: at compiler.run (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/react-scripts/scripts/build.js:169:23)
remote: at finalCallback (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/webpack/lib/Compiler.js:210:39)
remote: at hooks.done.callAsync.err (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/webpack/lib/Compiler.js:226:13)
remote: at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
remote: at AsyncSeriesHook.lazyCompileHook (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/tapable/lib/Hook.js:154:20)
remote: at onCompiled (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/webpack/lib/Compiler.js:224:21)
remote: at hooks.afterCompile.callAsync.err (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/webpack/lib/Compiler.js:553:14)
remote: at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
remote: at AsyncSeriesHook.lazyCompileHook (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/tapable/lib/Hook.js:154:20)
remote: at compilation.seal.err (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/webpack/lib/Compiler.js:550:30)
remote: at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
remote: at AsyncSeriesHook.lazyCompileHook (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/tapable/lib/Hook.js:154:20)
remote: at hooks.optimizeAssets.callAsync.err (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/webpack/lib/Compilation.js:1295:35)
remote: at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/tapable/lib/HookCodeFactory.js:32:10), <anonymous>:6:1)
remote: at AsyncSeriesHook.lazyCompileHook (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/tapable/lib/Hook.js:154:20)
remote: at hooks.optimizeChunkAssets.callAsync.err (/tmp/build_1c67c2822e7364298c69e79a4318103a/client/node_modules/webpack/lib/Compilation.js:1286:32)
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.tUXJH/_logs/2019-02-03T01_53_57_344Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! jordanwebsite@1.0.0 heroku-postbuild: `cd client && NPM_CONFIG_PRODUCTION=false npm install && npm run build`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the jordanwebsite@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.tUXJH/_logs/2019-02-03T01_53_57_358Z-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: Some possible problems:
remote:
remote: - Node version not specified in package.json
remote: https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
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 jorrharris-website.
remote:
To https://git.heroku.com/jorrharris-website.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/jorrharris-website.git'
回答1:
I had the same exact problem. I removed my package-lock from .git-ignore and it worked. Hope it helps.
回答2:
I had the same problem. I tried many suggestions from many posts and what finally did it for me was to run "npm install terser@3.14.1 --save-dev" in the client folder and then add "npm install terser@3.14.1 --prefix client" to the heroku-postbuild in the main package.json. It should now read:
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm install terser@3.14.1 --prefix client && npm run build --prefix client"
This is assuming that the main file directories handle the Mongo,Express and Node and then a client folder handles the React. Hope this works.
来源:https://stackoverflow.com/questions/54499380/mern-stack-push-to-heroku-remote-rejected-master-master-pre-receive-hoo