【问题标题】:How to fix 'failed to compile Node.js app' error on heroku如何修复heroku上的“编译Node.js应用程序失败”错误
【发布时间】:2021-07-01 00:43:43
【问题描述】:

所以我创建了一个 Mern 项目并希望它部署在 heroku 上。但无论我做什么,推动都被拒绝。它总是以错误“推送被拒绝,无法编译 Node.js 应用程序”结束。

这是我的 package.json 文件:

{
  "name": "ecom",
  "version": "1.0.0",
  "description": "e-commerce Website",
  "main": "server.js",
  "engines": {
    "node": "10.16.0"
  },
  "scripts": {
    "start": "node backend/server.js",
    "server": "nodemon backend/server.js",
    "client": "npm start  --prefix frontend",
    "build": "npm install --prefix frontend && npm run build --prefix frontend",
    "dev": "concurrently \"npm run server\" \"npm run client\"",
    "data:import": "node backend/seederScript.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "date-fns": "^2.19.0",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "mongoose": "^5.12.2",
    "react-scripts": "^4.0.3"
  },
  "devDependencies": {
    "concurrently": "^6.0.0",
    "nodemon": "^2.0.7"
  }
}

这是我的 github 存储库:https://github.com/gambhir-harshil/E-commerce

这是错误的完整日志:

-----> Building on the Heroku-20 stack
-----> Determining which buildpack to use for this app
-----> Node.js app detected
       
-----> Creating runtime environment
       
       NPM_CONFIG_LOGLEVEL=error
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       
-----> Installing binaries
       engines.node (package.json):  10.16.0
       engines.npm (package.json):   unspecified (use default)
       
       Resolving node version 10.16.0...
       Downloading and installing node 10.16.0...
       Using default npm version: 6.9.0
       
-----> Installing dependencies
       Installing node modules
       
       > core-js@2.6.12 postinstall /tmp/build_8817a311/node_modules/babel-runtime/node_modules/core-js
       > node -e "try{require('./postinstall')}catch(e){}"
       
       Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!
       
       The project needs your help! Please consider supporting of core-js on Open Collective or Patreon: 
       > https://opencollective.com/core-js 
       > https://www.patreon.com/zloirock 
       
       Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)
       
       
       > ejs@2.7.4 postinstall /tmp/build_8817a311/node_modules/ejs
       > node ./postinstall.js
       
       Thank you for installing EJS: built with the Jake JavaScript build tool (https://jakejs.com/)
       
       
       > core-js@3.10.0 postinstall /tmp/build_8817a311/node_modules/core-js
       > node -e "try{require('./postinstall')}catch(e){}"
       
       
       > core-js-pure@3.10.0 postinstall /tmp/build_8817a311/node_modules/core-js-pure
       > node -e "try{require('./postinstall')}catch(e){}"
       
       
       > nodemon@2.0.7 postinstall /tmp/build_8817a311/node_modules/nodemon
       > node bin/postinstall || exit 0
       
       Love nodemon? You can now support the project via the open collective:
        > https://opencollective.com/nodemon/donate
       
       added 1930 packages in 24.695s
       
-----> Build
       Running build
       
       > ecom@1.0.0 build /tmp/build_8817a311
       > npm install --prefix frontend && npm run build --prefix frontend
       
       
       > core-js@2.6.12 postinstall /tmp/build_8817a311/frontend/node_modules/babel-runtime/node_modules/core-js
       > node -e "try{require('./postinstall')}catch(e){}"
       
       
       > core-js@3.10.0 postinstall /tmp/build_8817a311/frontend/node_modules/core-js
       > node -e "try{require('./postinstall')}catch(e){}"
       
       
       > core-js-pure@3.10.0 postinstall /tmp/build_8817a311/frontend/node_modules/core-js-pure
       > node -e "try{require('./postinstall')}catch(e){}"
       
       
       > ejs@2.7.4 postinstall /tmp/build_8817a311/frontend/node_modules/ejs
       > node ./postinstall.js
       
       added 1885 packages from 819 contributors and audited 1889 packages in 52.962s
       found 0 vulnerabilities
       
       
       > frontend@0.1.0 build /tmp/build_8817a311/frontend
       > react-scripts build
       
       Creating an optimized production build...
       Failed to compile.
       
       ./node_modules/@material-ui/icons/utils/createSvgIcon.js
       Cannot find module: '@material-ui/core/utils'. Make sure this package is installed.
       
       You can install this package by running: npm install @material-ui/core/utils.
       
       
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! frontend@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the frontend@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/npmcache.pNfTf/_logs/2021-04-05T04_59_12_835Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ecom@1.0.0 build: `npm install --prefix frontend && npm run build --prefix frontend`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ecom@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/npmcache.pNfTf/_logs/2021-04-05T04_59_12_851Z-debug.log
-----> Build failed
       
       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys
       
       Some possible problems:
       
       - A module may be missing from 'dependencies' in package.json
         https://devcenter.heroku.com/articles/troubleshooting-node-deploys#ensure-you-aren-t-relying-on-untracked-dependencies
       
       Love,
       Heroku
       
 !     Push rejected, failed to compile Node.js app.
 !     Push failed

【问题讨论】:

    标签: node.js reactjs github heroku npm


    【解决方案1】:

    build 脚本引用了client,但client 目录不存在。它应该是frontend。

    "build": "npm install --prefix frontend && npm run build --prefix frontend"
    

    【讨论】:

    • 谢谢,我没有注意到,但这并没有帮助。我更新了日志,又出现同样的错误。
    • 没关系@material-ui/core 丢失了,谢谢!
    猜你喜欢
    • 2019-09-03
    • 2020-12-13
    • 1970-01-01
    • 2013-05-02
    • 2020-11-29
    • 2017-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多