找不到模块“ /app/index.js”。架构或package.json问题?

时间:2019-01-07 18:48:32

标签: javascript reactjs heroku architecture package.json

我的投资组合网站在我的本地计算机上运行良好,但是当我将其上传到heroku时,出现错误:找不到模块'/app/index.js', 我搜索了论坛。所有帖子都通过不定义“开始”脚本来说明这一点。我试图修改它。所以要么我做错了,要么是另一个问题:

控制台错误

2019-01-07T17:47:26.415503+00:00 heroku[web.1]: State changed from starting to crashed
2019-01-07T17:47:26.423981+00:00 heroku[web.1]: State changed from crashed to starting
2019-01-07T17:47:26.067633+00:00 app[web.1]:
2019-01-07T17:47:26.067658+00:00 app[web.1]: > portfoliopro@1.0.0 start /app
2019-01-07T17:47:26.067660+00:00 app[web.1]: > node index.js
2019-01-07T17:47:26.067661+00:00 app[web.1]:
2019-01-07T17:47:26.233543+00:00 app[web.1]: internal/modules/cjs/loader.js:596
2019-01-07T17:47:26.233546+00:00 app[web.1]: throw err;
2019-01-07T17:47:26.233548+00:00 app[web.1]: ^
2019-01-07T17:47:26.233550+00:00 app[web.1]:
2019-01-07T17:47:26.233551+00:00 app[web.1]: Error: Cannot find module '/app/index.js'
2019-01-07T17:47:26.233553+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15)
2019-01-07T17:47:26.233555+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:520:25)
2019-01-07T17:47:26.233557+00:00 app[web.1]: at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)
2019-01-07T17:47:26.233558+00:00 app[web.1]: at startup (internal/bootstrap/node.js:238:19)
2019-01-07T17:47:26.233560+00:00 app[web.1]: at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
2019-01-07T17:47:26.251625+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-01-07T17:47:26.252289+00:00 app[web.1]: npm ERR! errno 1
2019-01-07T17:47:26.254346+00:00 app[web.1]: npm ERR! portfoliopro@1.0.0 start: `node index.js`
2019-01-07T17:47:26.254615+00:00 app[web.1]: npm ERR! Exit status 1
2019-01-07T17:47:26.257782+00:00 app[web.1]: npm ERR!
2019-01-07T17:47:26.258085+00:00 app[web.1]: npm ERR! Failed at the portfoliopro@1.0.0 start script.
2019-01-07T17:47:26.258344+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-01-07T17:47:26.284988+00:00 app[web.1]:
2019-01-07T17:47:26.286884+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-01-07T17:47:26.287433+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-01-07T17_47_26_260Z-debug.log
2019-01-07T17:47:40.055001+00:00 heroku[web.1]: Starting process with command `npm start`
2019-01-07T17:47:43.603856+00:00 app[web.1]:
2019-01-07T17:47:43.603892+00:00 app[web.1]: > portfoliopro@1.0.0 start /app
2019-01-07T17:47:43.603895+00:00 app[web.1]: > node index.js
2019-01-07T17:47:43.603896+00:00 app[web.1]:
2019-01-07T17:47:43.954899+00:00 app[web.1]: internal/modules/cjs/loader.js:596
2019-01-07T17:47:43.954941+00:00 app[web.1]: throw err;
2019-01-07T17:47:43.954943+00:00 app[web.1]: ^
2019-01-07T17:47:43.954945+00:00 app[web.1]:
2019-01-07T17:47:43.954947+00:00 app[web.1]: Error: Cannot find module '/app/index.js'

客户端package.json

  "scripts": {
    "start": "node scripts/start.js",
    "build": "node scripts/build.js",
    "test": "node scripts/test.js"
  },
  "proxy": "http://localhost:5000/",
  "eslintConfig": {
    "extends": "react-app"
  },

服务器端package.json

{
  "name": "portfoliopro",
  "version": "1.0.0",
  "main": "index.js",
  "engines": {
    "node": "10.4.0",
    "npm": "6.2.0"
  },
  "scripts": {
    "start": "node index.js",
    "server": "nodemon server.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"
  },
  "dependencies": {
    "body-parser": "^1.18.3",
    "dotenv": "^6.1.0",
    "express": "^4.16.4",
    "nodemailer": "^4.7.0",
    "nodemon": "^1.18.9",
    "xoauth2": "^1.2.0"
  },
  "devDependencies": {
    "concurrently": "^4.0.1"
  }
}

文件结构图像(托管了stackoverflow) file structure

还请注意,我在客户端将启动命令设置为“ start”:“ node scripts / start.js”,当我将其更改为“ react-scripts start”时,我知道它是一种更好的做法- “ npm run dev”仅在服务器上运行的本地时间段。

顺便说一句,上传时我也得到这个: 远程:error-ex@1.3.2 / tmp / build_8302bae019d1d3a1f79b88a8bca2b16d / node_modules / error-ex 我找不到答案。

非常感谢所有帮手。

0 个答案:

没有答案