我使用node.js + react制作了一个应用程序,但无法在heroku上部署它。 它在本地主机上工作 我试图删除package-lock.json文件,但没有帮助。
这是我在服务器目录下package.json中的脚本
"scripts": {
"start": "node index.js",
"server": "nodemon index.js",
"client": "npm run 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"
和我的heroku日志
*
-----> Node.js app detected -----> Creating runtime environment NPM_CONFIG_LOGLEVEL=error NODE_ENV=production NODE_MODULES_CACHE=true NODE_VERBOSE=false -----> Installing binaries engines.node (package.json): 8.1.1 engines.npm (package.json): 5.0.3 Resolving node version 8.1.1... Downloading and installing node 8.1.1... npm 5.0.3 already installed with node -----> Restoring cache - node_modules -----> Installing dependencies Installing node modules (package.json + package-lock) added 93 packages in 7.456s -----> Build Running heroku-postbuild > server@1.0.0 heroku-postbuild /tmp/build_52aeb2bcb298df1839239655d0215864 > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client > fsevents@1.2.9 install /tmp/build_52aeb2bcb298df1839239655d0215864/client/node_modules/jest-haste-map/node_modules/fsevents > node install > fsevents@1.2.9 install /tmp/build_52aeb2bcb298df1839239655d0215864/client/node_modules/chokidar/node_modules/fsevents > node install > core-js-pure@3.1.4 postinstall /tmp/build_52aeb2bcb298df1839239655d0215864/client/node_modules/core-js-pure > node scripts/postinstall || echo "ignore" > core-js@2.6.9 postinstall /tmp/build_52aeb2bcb298df1839239655d0215864/client/node_modules/babel-runtime/node_modules/core-js > node scripts/postinstall || echo "ignore" added 1550 packages in 43.208s > client@0.1.0 build /tmp/build_52aeb2bcb298df1839239655d0215864/client > react-scripts build /tmp/build_52aeb2bcb298df1839239655d0215864/client/node_modules/@hapi/hoek/lib/deep-equal.js:17 options = { prototype: true, ...options }; ^^^ SyntaxError: Unexpected token ... at createScript (vm.js:74:10) at Object.runInThisContext (vm.js:116:10) at Module._compile (module.js:533:28) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:503:32) at tryModuleLoad (module.js:466:12) at Function.Module._load (module.js:458:3) at Module.require (module.js:513:17) at require (internal/module.js:11:18) at Object.<anonymous> (/tmp/build_52aeb2bcb298df1839239655d0215864/client/node_modules/@hapi/hoek/lib/index.js:9:19) at Module._compile (module.js:569:30) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:503:32) at tryModuleLoad (module.js:466:12) at Function.Module._load (module.js:458:3) at Module.require (module.js:513:17) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! client@0.1.0 build: `react-scripts build`
npm错误!退出状态1 npm ERR! npm ERR!在client@0.1.0上失败 构建脚本。 npm ERR! npm可能不是问题。那里 可能是上面的其他日志记录输出。 npm ERR!完整的日志 该运行可在以下位置找到:npm ERR!
/tmp/npmcache.1V3q7/_logs/2019-06-21T10_03_50_779Z-debug.log npm错误! 代码ELIFECYCLE npm ERR! errno 1 npm错误!服务器@ 1.0.0 heroku-postbuild:NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
npm错误!退出状态1 npm 呃! npm ERR!在server@1.0.0 heroku-postbuild脚本上失败。 npm 呃! npm可能不是问题。有可能 上面的其他日志输出。 npm ERR!此运行的完整日志 可以在以下位置找到:npm ERR!
/tmp/npmcache.1V3q7/_logs/2019-06-21T10_03_50_793Z-debug.log ----->构建失败We're sorry this build is failing! You can troubleshoot common issues here: https://devcenter.heroku.com/articles/troubleshooting-node-deploys If you're stuck, please submit a ticket so we can help: https://help.heroku.com/ Love, Heroku ! Push rejected, failed to compile Node.js app. ! Push failed*
答案 0 :(得分:-1)
您不需要删除package.json文件。您只需要上载除node_modules以外的所有文件和文件夹。 Heroku服务器会为您安装所有必需的软件包。
还有一件事,您必须在scripts标记下添加“ test”命令。
"scripts": {
"test": "node index.js",
"start": "node index.js"
},