Node.js错误:找不到模块表达

德米特里

我写了我的第一个node.js应用程序,但是找不到快速库:

C:\ChatServer\Server>node server.js

module.js:340
    throw err;
          ^
Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\ChatServer\Server\server.js:6:9)
    at Object.<anonymous> (C:\ChatServer\Server\server.js:25:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

但是express已安装(带有-g密钥):

C:\ChatServer\Server>npm install -g express
npm http GET https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/connect/2.7.11
npm http GET https://registry.npmjs.org/commander/0.6.1
npm http GET https://registry.npmjs.org/range-parser/0.0.4
npm http GET https://registry.npmjs.org/mkdirp/0.3.4
npm http GET https://registry.npmjs.org/cookie/0.1.0
npm http GET https://registry.npmjs.org/buffer-crc32/0.2.1
npm http GET https://registry.npmjs.org/fresh/0.1.0
npm http GET https://registry.npmjs.org/methods/0.0.1
npm http GET https://registry.npmjs.org/send/0.1.0
npm http GET https://registry.npmjs.org/cookie-signature/1.0.1
npm http GET https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/mkdirp/0.3.4
npm http 304 https://registry.npmjs.org/range-parser/0.0.4
npm http 304 https://registry.npmjs.org/cookie/0.1.0
npm http 304 https://registry.npmjs.org/connect/2.7.11
npm http 304 https://registry.npmjs.org/commander/0.6.1
npm WARN package.json [email protected] No repository field.
npm http 304 https://registry.npmjs.org/buffer-crc32/0.2.1
npm http 304 https://registry.npmjs.org/fresh/0.1.0
npm http 304 https://registry.npmjs.org/methods/0.0.1
npm http 304 https://registry.npmjs.org/send/0.1.0
npm http 304 https://registry.npmjs.org/cookie-signature/1.0.1
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No readme data.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm http 304 https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/mime/1.2.6
npm http GET https://registry.npmjs.org/qs/0.6.5
npm http GET https://registry.npmjs.org/send/0.1.1
npm http GET https://registry.npmjs.org/formidable/1.0.14
npm http GET https://registry.npmjs.org/cookie/0.0.5
npm http GET https://registry.npmjs.org/bytes/0.2.0
npm http GET https://registry.npmjs.org/pause/0.0.1
npm http 304 https://registry.npmjs.org/mime/1.2.6
npm http 304 https://registry.npmjs.org/bytes/0.2.0
npm WARN package.json [email protected] No repository field.
npm http 304 https://registry.npmjs.org/pause/0.0.1
npm WARN package.json [email protected] No repository field.
npm http 304 https://registry.npmjs.org/formidable/1.0.14
npm http 304 https://registry.npmjs.org/qs/0.6.5
npm http 304 https://registry.npmjs.org/send/0.1.1
npm http 304 https://registry.npmjs.org/cookie/0.0.5
npm http GET https://registry.npmjs.org/mime
npm http 304 https://registry.npmjs.org/mime
C:\Users\Dmitry\AppData\Roaming\npm\express -> C:\Users\Dmitry\AppData\Roaming\npm\node_modules\express\bin\express
npm WARN package.json [email protected] 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
[email protected] C:\Users\Dmitry\AppData\Roaming\npm\node_modules\express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])

一些信息:

C:\ChatServer\Server>npm --version
1.2.24

C:\ChatServer\Server>node --version
v0.10.9

C:\ChatServer\Server>npm --version
1.2.24

C:\ChatServer\Server>npm ls -g installed express
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
npm WARN package.json [email protected] No repository field.
C:\Users\Dmitry\AppData\Roaming\npm
└── [email protected]


C:\ChatServer\Server>npm ls installed express
C:\ChatServer\Server
└── (empty)

我怎么解决这个问题?必须安装时不带-g吗?)

高洛·罗登(Golo Roden)

您需要在本地将Express安装到应用程序(node_modules文件夹)的上下文中

$ npm install express

原因是应用程序总是在其本地上下文中查找任何依赖项。全局安装仅用于设置系统范围内的可用二进制文件,例如单元测试运行程序或引导程序或类似的程序。

使用Express,在全局进行安装时,会获得一个express二进制文件,可以为您引导一个应用程序。有关更多信息,请键入

$ express --help

因此,要回答您的最后一个问题:,您需要不安装-g

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章