nodejs express 启动报错 Error Cannot find module 'xxx'

nodejs express 启动报错:Error: Cannot find module ‘xxx‘,这是因为缺少模块的引用。

比如我在代码中使用了‘express-session‘,但是却没有在 package.json 文件的 "dependencies" 项中添加 ‘express-session‘ 的依赖

D:\nodejs\myapp>set DEBUG=myapp & npm start

> myapp@0.0.0 start D:\nodejs\myapp
> node ./bin/www

module.js:340
    throw err;
    ^

Error: Cannot find module ‘express-session‘
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:289:25)
    at Module.require (module.js:366:17)
    at require (module.js:385:17)
    at Object.<anonymous> (D:\nodejs\myapp\app.js:6:15)
    at Module._compile (module.js:435:26)
    at Object.Module._extensions..js (module.js:442:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:313:12)
    at Module.require (module.js:366:17)

package.json 文件

{
  "name": "myapp",
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "start": "node ./bin/www"
  },
  "dependencies": {
    "body-parser": "~1.15.2",
    "cookie-parser": "~1.4.3",
    "debug": "~2.2.0",
    "ejs": "^2.5.5",
    "express": "~4.14.0",
    "express-session": "^1.14.2",
    "mongoose": "^4.7.6",
    "morgan": "~1.7.0",
    "serve-favicon": "~2.3.0"
  }
}

如果你手动在 package.json 文件中添加依赖的话,就需要在你的项目目录(我的目录是:D:\nodejs\myapp)下执行:npm install

还有一个方法是执行:npm install 模块名称 --save

D:\nodejs\myapp>npm install express-session --save
express-session@1.14.2 node_modules\express-session
├── on-headers@1.0.1
├── cookie-signature@1.0.6
├── utils-merge@1.0.0
├── cookie@0.3.1
├── parseurl@1.3.1
├── depd@1.1.0
├── crc@3.4.1
└── uid-safe@2.1.3 (base64-url@1.3.3, random-bytes@1.0.0)

记得把我这里提到的‘xxx‘或 ‘express-session‘ 替换为你遇到 的错误信息中提示的模块名称哦!

======================文档信息===========================

版权声明:非商用自由转载-保持署名-注明出处

署名(BY) :testcs_dn(微wx笑)

文章出处:[无知人生,记录点滴](http://blog.csdn.net/testcs_dn)

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!http://www.captainbed.net

nodejs express 启动报错 Error Cannot find module 'xxx'

原文地址:https://www.cnblogs.com/skiwndhed/p/10469937.html

时间: 2024-10-29 19:07:15

nodejs express 启动报错 Error Cannot find module 'xxx'的相关文章

源码安装mysql5.6x启动报错:[ERROR] Can&#39;t find messagefile &#39;/data/mysqldata/3306/english/errmsg.sys&#39;

170502 10:43:40 mysqld_safe Starting mysqld daemon with databases from /data/mysqldata/3306/data 2017-05-02 10:43:40 0 [Warning] The syntax '--language/-l' is deprecated and will be removed in a future release. Please use '--lc-messages-dir' instead.

springboot启动报错:&quot;Error starting ApplicationContext. To display the conditions report re-run your application with &#39;debug&#39; enabled.&quot;

报错内容 java.lang.Object.wait(Native Method)java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:143)com.mysql.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:41)2019-02-14 14:58:00.326 INFO 17688 --- [ main] Condition

全局安装的 webpack运行时 报错 Error: Cannot find module &#39;webpack&#39; ......

全局安装的webpack   安装指令如下 cnpm install wepack -save-dev -g 但是 在我的项目空间运行webpack指令的时候 会报如下错误 为了方便抓取{ Error: Cannot find module 'webpack' at Function.Module._resolveFilename (module.js:527:15) at Function.Module._load (module.js:476:23) at Module.require (m

webpack使用babel报错:Error: Cannot find module &#39;@babel/core&#39;

这两天再回顾配置webpack,当使用到webpack配置babel时候报错了.没有找到babel/core 查看了一下文档,才发现,是因为版本问题 默认babel-loader | babel对应的版本需要一致.所以回退到@7版本就可以.. npm install -D [email protected]7 babel-core babel-preset-env 这样就解决啦. webpack使用babel报错:Error: Cannot find module '@babel/core' 原

mysql登陆启动报错 ERROR 2002 (HY000) 解决方法

报错信息 登陆数据库报错:` ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2 "No such file or directory")` 重启服务报错:Job for mariadb.service failed because the control process exited with error code. See &quo

IntelliJ IDEA 14.1.4导入项目启动报错:Error during artifact deployment.[组件部署期间出错]

1.问题描述:Error during artifact deployment.[组件部署期间出错] 2.删除Artifacts 3.刷新 4.重新生成Artifacts 5.重新选择 再重新启动项目即可.

Rabbitmq 服务启动后停止 | Windows下启动报错Error: unable to connect to node [email&#160;protected]: nodedown

1.erlang版本和rabbitmq版本不匹配 版本匹配: http://www.rabbitmq.com/which-erlang.html 2.找到匹配的版本,卸载当前rabbitmq重新安装. 执行以下操作从计算机中完全卸载RabbitMQ和Erlang: (1)打开Windows控制面板,双击“程序和功能”. (2)在当前安装的程序列表中,右键单击RabbitMQ Server,然后单击“卸载”. (3)在当前安装的程序列表中,右键单击“Erlang OTP”,然后单击“卸载”. (4

android sdk启动报错error: could not install *smartsocket* listener: cannot bind to 127.0.0.1:5037:

问题原因:端口5037被占用 解决方案: 方式一:可以用cmd命令 C:\Users\Administrator>netstat-ano | findstr "5037"                 <<<<<-------------查看5037 被谁占用,然后杀掉 TCP   127.0.0.1:5037        0.0.0.0:0             LISTENING       4524 TCP   127.0.0.1:503

canal启动报错ERROR c.a.o.canal.parse.inbound.mysql.dbsync.DirectLogFetcher - I/O error while reading from client socket

原文地址:https://www.cnblogs.com/xiaostudy/p/11286940.html