Heroku 缺少模块 [英] Heroku missing module

查看:118
本文介绍了Heroku 缺少模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个简单的 node.js 服务器部署到 Heroku,但一直遇到此错误:

I'm trying to deploy a simple node.js server to Heroku, but keep running into this error:

Error: Cannot find module 'morgan'

我正在使用 morgan 来做一些 HTTP 日志记录,我在我的 package.json 下的 devDependencies(以及许多其他)中有 morgan

I'm using morgan to do some HTTP logging, i have morgan in my package.json under the devDependencies (along with many others)

"devDependencies": {
    "morgan": "~1.5.0"
}

我可以在本地执行 npm install 并在没有任何问题的情况下启动服务器,但是当我部署到 Heroku 时,一旦启动服务器,我就会遇到该错误.

I can do npm install locally and start the server without any issues, but when I deploy to Heroku I keep running into that error once it starts the server.

有什么我忘记了吗?

推荐答案

默认情况下 Heroku 执行 npm install --production 避免安装 devDependencies,直接引用 Heroku 的文档.

By default Heroku execute npm install --production which avoid install devDependencies, quoting literally documentation of Heroku.

Heroku 节点 buildpack 运行 npm install --production,它不会在 package.json 文件中安装 devDependencies.如果您希望在部署到 Heroku 时安装开发依赖项,您应该将构建依赖项(例如 grunt 插件)从 devDependencies 移动到 package.json 中的依赖项.

The Heroku node buildpack runs npm install --production, which doesn’t install devDependencies in your package.json file. If you wish to install development dependencies when deploying to Heroku, you should move your build dependencies (such as grunt plugins) from devDependencies to dependencies in package.json.

如果您使用 Morgan 模块,则需要将其移至依赖项".

If you use the Morgan module, you need move it to 'dependencies'.

来源:https://devcenter.heroku.com/articles/nodejs-support

这篇关于Heroku 缺少模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆