将React / Node应用程序推送到Heroku时,不断出现“找不到模块”错误

时间:2019-08-18 22:13:00

标签: node.js reactjs heroku npm

我正在尝试使用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.


1 个答案:

答案 0 :(得分:0)

Atom的评论对我有所帮助,但我是新来的,因此无法在此处写下。 将heroku-postbuild更改为“ cd客户端&& npm install && npm run build”,并将node-sass添加到服务器package.json也解决了我的问题!