【问题标题】:Heroku NodeJS cannot find moduleHeroku NodeJS 找不到模块
【发布时间】:2018-06-20 01:34:43
【问题描述】:

我有一个应用程序在本地运行良好,但在部署时无法运行。 消息是

Error: Cannot find module 'jsonwebtoken'

即使我在 package.json 的“依赖项”中有它(不是 devdependency)

我尝试了“heroku run bash”并验证了 jsonwebtoken 存在于 node_modules 文件夹中。
最后我尝试了“heroku local web”,它工作正常。 但是由于某种原因,它在部署时永远不会起作用。

这是需要jsonwebtoken的文件的开头

var mongoose = require('mongoose');
var crypto = require('crypto');
console.log('check1');
var jwt = require('jsonwebtoken');
console.log('check2');

它到达“check1”而不是“check2”

这是我的 package.json

{
  "name": "loc8r",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "engines": {
    "node": "~0.10.13",
    "npm": "~1.3.2"
  },
  "dependencies": {
    "body-parser": "~1.8.1",
    "cookie-parser": "~1.3.3",
    "debug": "^2.0.0",
    "dotenv": "^4.0.0",
    "express": "~4.9.0",
    "express-jwt": "^5.3.0",
    "jade": "~1.6.0",
    "jsonwebtoken": "^8.1.0",
    "mongoose": "^4.13.5",
    "morgan": "~1.3.0",
    "passport": "^0.4.0",
    "passport-local": "^1.0.0",
    "request": "~2.51.0",
    "serve-favicon": "~2.1.3",
    "uglify-js": "~2.4.15"
  },
  "description": "myapp",
  "main": "app.js",
  "devDependencies": {},
  "keywords": [],
  "author": "",
  "license": "ISC"
}

有人可以帮我弄清楚发生了什么吗?

【问题讨论】:

  • 能不能把需要module和package.json的文件粘贴进去
  • 已编辑。谢谢!

标签: node.js heroku module json-web-token


【解决方案1】:

从 jsonwebtoken 的package.json 来看,你在 Heroku 上使用的节点版本太旧了。我建议升级到最新版本。

我很确定它适用于您本地,因为您在自己的计算机上运行比 0.10.X 更新的版本。

【讨论】:

    猜你喜欢
    • 2012-03-08
    • 1970-01-01
    • 2015-09-21
    • 1970-01-01
    • 2017-12-16
    • 2014-01-29
    • 1970-01-01
    • 2016-07-31
    相关资源
    最近更新 更多