【问题标题】:Keep getting "cannot find module" errors when pushing React/Node app to Heroku将 React/Node 应用程序推送到 Heroku 时不断收到“找不到模块”错误
【发布时间】:2019-12-24 04:49:42
【问题描述】:

我正在尝试使用 create-react-app 和 Node 将我使用 React 构建的网站发布到 Heroku,但它在 node-sass@4.12.0 安装脚本中一直失败。

我试过 npm install mkdirp ,它说它丢失了,当我这样做时,我得到了同样的错误,除了它在寻找“glob”。我安装了它,然后它在寻找“aproba”。我知道继续手动安装这些软件包不是解决方案。

这是我的 package.json 文件。我为客户端和服务器设置了两个,它们位于两个不同的文件夹中。

{
  "name": "client",
  "version": "1.0.0",
  "private": true,
  "proxy": "http://localhost:5000/",
  "description": "",
  "main": "src/index.js",
  "dependencies": {
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-router-dom": "^5.0.1",
    "react-scripts": "^3.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "node-sass": "^4.12.0"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "author": "",
  "license": "ISC"
}

{
  "name": "server",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "author": "",
  "license": "MIT",
  "scripts": {
    "start": "node server/server.js",
    "heroku-postbuild": "cd client && npm install --only=dev && npm install && npm run build",
    "server": "nodemon server/server.js",
    "client": "npm run start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  },
  "dependencies": {
    "body-parser": "^1.18.3",
    "concurrently": "^3.5.1",
    "cors": "^2.8.5",
    "express": "^4.16.3",
    "mysql": "^2.16.0"
  },
  "devDependencies": {
    "nodemon": "^1.17.4",
    "react-router": "^5.0.1",
    "react-router-dom": "^5.0.1"
  }
}

这是我得到的错误:

remote: -----> Build
remote:        Running heroku-postbuild
remote:        
remote:        > server@1.0.0 heroku-postbuild /tmp/build_fa529f4bf2bafed6f44f8aecf630696b
remote:        > cd client && npm install --only=dev && npm install && npm run build
remote:        
remote:        
remote:        > node-sass@4.12.0 install /tmp/build_fa529f4bf2bafed6f44f8aecf630696b/client/node_modules/node-sass
remote:        > node scripts/install.js
remote:        
remote: internal/modules/cjs/loader.js:638
remote:     throw err;
remote:     ^
remote: 
remote: Error: Cannot find module 'mkdirp'
remote:     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
remote:     at Function.Module._load (internal/modules/cjs/loader.js:562:25)
remote:     at Module.require (internal/modules/cjs/loader.js:692:17)
remote:     at require (internal/modules/cjs/helpers.js:25:18)
remote:     at Object.<anonymous> (/tmp/build_fa529f4bf2bafed6f44f8aecf630696b/client/node_modules/node-sass/scripts/install.js:7:11)
remote:     at Module._compile (internal/modules/cjs/loader.js:778:30)
remote:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
remote:     at Module.load (internal/modules/cjs/loader.js:653:32)
remote:     at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
remote:     at Function.Module._load (internal/modules/cjs/loader.js:585:3)
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 1
remote: npm ERR! node-sass@4.12.0 install: `node scripts/install.js`
remote: npm ERR! Exit status 1
remote: npm ERR! 
remote: npm ERR! Failed at the node-sass@4.12.0 install script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.


【问题讨论】:

  • 我通过将 heroku-postbuild 更改为“cd client && npm install && npm run build”并将 node-sass 添加到服务器 package.json 解决了这个问题。

标签: node.js reactjs heroku npm


【解决方案1】:

Atom 的评论帮助了我,但我是新手,不能在那里写这个。 将 heroku-postbuild 更改为“cd client && npm install && npm run build”并将 node-sass 添加到服务器 package.json 也解决了我的问题!

【讨论】:

    猜你喜欢
    • 2019-11-07
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 2022-07-17
    • 2018-09-03
    • 2020-06-09
    • 1970-01-01
    • 2020-05-19
    相关资源
    最近更新 更多