Heroku-部署时找不到knex

时间:2019-12-12 19:23:50

标签: javascript node.js heroku deployment knex.js

将应用程序部署到Heroku时遇到问题。我已经做了无数次了,直到现在一直运转良好。突然,我开始遇到一些问题(但是在本地,它就像一个魅力!)。将应用程序部署到Heroku并运行node index.js时,我收到错误消息:

Error: Cannot find module './knex'
Require stack:
- /app/node_modules/knex/lib/index.js
- /app/node_modules/knex/knex.js
- /app/src/domain/database/KnexConnection.js
- /app/src/routing/cities/CitiesDB.js
- /app/src/routing/cities/CitiesAPI.js
- /app/src/routing/Routes.js
- /app/src/routing/index.js
- /app/index.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
    at Function.Module._load (internal/modules/cjs/loader.js:690:27)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/app/node_modules/knex/lib/index.js:8:14)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Module.require (internal/modules/cjs/loader.js:852:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/app/node_modules/knex/lib/index.js',
    '/app/node_modules/knex/knex.js',
    '/app/src/domain/database/KnexConnection.js',
    '/app/src/routing/cities/CitiesDB.js',
    '/app/src/routing/cities/CitiesAPI.js',
    '/app/src/routing/Routes.js',
    '/app/src/routing/index.js',
    '/app/index.js'
  ]
}

在部署应用程序之前,我从未见过此错误。甚至在我部署该应用程序的两天前,都没有遇到任何较大的问题。从那时起,我所做的更改是我安装了axios以从节点应用程序调用第三方。

我的package.json看起来像这样:

{
  "name": "tefoWebService",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "jest --forceExit",
    "start": "nodemon index.js --development"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/orzech1907/tefoWebService.git"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/orzech1907/tefoWebService/issues"
  },
  "homepage": "https://github.com/orzech1907/tefoWebService#readme",
  "dependencies": {
    "bugsnag": "^2.4.3",
    "hapi": "^17.5.1",
    "hapi-auth-jwt2": "^8.1.0",
    "joi": "^13.4.0",
    "jsonwebtoken": "^8.3.0",
    "knex": "^0.16.3",
    "nodemon": "^1.17.5",
    "pg": "^7.4.3" 
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-es2015": "^6.24.1",
    "chai": "^4.2.0",
    "chai-http": "^4.2.0",
    "jest": "^23.6.0",
    "rimraf": "^2.6.2"
  }
}

我已经尝试通过运行heroku run npm i -g knex在Heroku上全局安装knex,但没有效果,当我尝试启动迁移时,我遇到了另一个问题:

Error: Cannot find module './normalize-options.js'
Require stack:
- /app/node_modules/resolve/lib/async.js
- /app/node_modules/resolve/index.js
- /app/node_modules/liftoff/index.js
- /app/node_modules/knex/bin/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
    at Function.Module._load (internal/modules/cjs/loader.js:690:27)
    at Module.require (internal/modules/cjs/loader.js:852:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/app/node_modules/resolve/lib/async.js:5:24)
    at Module._compile (internal/modules/cjs/loader.js:959:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
    at Module.load (internal/modules/cjs/loader.js:815:32)
    at Function.Module._load (internal/modules/cjs/loader.js:727:14)
    at Module.require (internal/modules/cjs/loader.js:852:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/app/node_modules/resolve/lib/async.js',
    '/app/node_modules/resolve/index.js',
    '/app/node_modules/liftoff/index.js',
    '/app/node_modules/knex/bin/cli.js'
  ]
}

有人知道这里可能是什么问题吗?为什么我的node.js应用程序可以在本地计算机上运行,​​而在Heroku上却异常运行?

-编辑-

问题解决了。 axios导致了我的问题。我必须更改第三方集成的实现。

0 个答案:

没有答案