您如何在Heroku应用程序上获得快递服务?

时间:2019-05-24 16:47:02

标签: node.js express heroku npm

我在Heroku上有一个应用程序,当我运行node server.js时,它抛出一个错误并说错误:找不到模块'express'。

我已经清除了npm缓存,重建了应用程序,检查了package.json和依赖项。对我没有什么帮助,我现在只是在寻找解决方案。

    throw err;
    ^

Error: Cannot find module 'express'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
    at Function.Module._load (internal/modules/cjs/loader.js:508:25)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.<anonymous> (/app/server.js:1:79)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)

尝试启动该应用。

这是package.json

{
  "name": "SCOGEAgent",
  "version": "0.0.0",
  "description": "A simple Blockstack app",
  "main": "index",
  "scripts": {
    "browserify": "browserify requires.js -o public/bundle.js",
    "start": "run browserify & node server.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/blockstack/hello-blockstack.git"
  },
  "author": "",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/blockstack/hello-blockstack/issues"
  },
  "homepage": "https://github.com/blockstack/hello-blockstack#readme",
  "devDependencies": {
    "browserify": "^14.1.0",
    "express": "^4.16.4",
    "opn": "^4.0.2"
  },
  "dependencies": {
    "browserify": "^14.1.0",
    "express": "^4.16.4",
    "opn": "^4.0.2",
    "@types/node": "^11.13.0",
    "blockstack": "^18.0.4",
    "express-ws": "^4.0.0",
    "json-pointer": "^0.6.0",
    "react-router-dom": "^5.0.0",
    "socket.io": "^2.2.0",
    "socket.io-client": "^2.2.0",
    "websocket-stream": "^5.5.0"
  }
}

1 个答案:

答案 0 :(得分:1)

Express应该放在您的dependencies中,而不是devDependencies中。这就是您知道放置第三方依赖项的位置的方法。

  • 该应用是否需要依赖项才能运行?将其放入dependencies
  • 应用是否需要依赖项来构建,测试,皮棉或其他任何内容 发展任务?将其放入devDependencies

只有当您需要在运行项目之前构建项目时,这种情况才会变得模糊。然后,您的某些构建依赖项可能放在dependencies中,而不是devDependencies中。我敢肯定有一种更专业的方法来管理此问题,但这就是我的方法。