node.js - NPM require ('tar' ) 找不到模块错误

标签 node.js npm

我使用 npm 安装了 tarfstream,之后运行了一些命令。输出是:

您的环境已设置为使用 Node.js 0.10.18 (ia32) 和 npm。

C:\Users\abc>npm --version
1.3.8

C:\Users\abc>npm list
C:\Users\abc
├── chrome-rdebug@0.0.9
├─┬ fstream@0.1.24
│ ├── graceful-fs@2.0.1
│ ├── inherits@2.0.1
│ ├── mkdirp@0.3.5
│ └── rimraf@2.2.2
├── mime@1.2.11
├── q@0.9.7
├─┬ request@2.27.0
│ ├── aws-sign@0.3.0
│ ├── cookie-jar@0.3.0
│ ├── forever-agent@0.5.0
│ ├─┬ form-data@0.1.1
│ │ ├── async@0.2.9
│ │ └─┬ combined-stream@0.0.4
│ │   └── delayed-stream@0.0.5
│ ├─┬ hawk@1.0.0
│ │ ├── boom@0.4.2
│ │ ├── cryptiles@0.2.2
│ │ ├── hoek@0.9.1
│ │ └── sntp@0.2.4
│ ├─┬ http-signature@0.10.0
│ │ ├── asn1@0.1.11
│ │ ├── assert-plus@0.1.2
│ │ └── ctype@0.5.2
│ ├── json-stringify-safe@5.0.0
│ ├── node-uuid@1.4.1
│ ├── oauth-sign@0.3.0
│ ├── qs@0.6.5
│ └── tunnel-agent@0.3.0
├─┬ tar@0.1.18
│ ├── block-stream@0.0.7
│ └── inherits@2.0.1
└─┬ ws@0.4.30
  ├── commander@0.6.1
  ├── nan@0.3.2
  ├── options@0.0.5
  └── tinycolor@0.0.1


C:\Users\abc>node --version
v0.10.18

现在在运行node.js时,当我执行require('tar')时,我得到了

> require('fstream')
Error: Cannot find module 'fstream'
    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 repl:1:2
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
> require('tar')
Error: Cannot find module 'tar'
    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 repl:1:2
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)

我应该做什么?

最佳答案

该错误意味着您正在尝试 require()目录中的那些模块永远不会解析为您显示的模块,即 C:\Users\abc\node_modules .

如果您位于类似 C:\Users\user2 的目录中,模块永远不会解析,因为模块将以这种方式检查:

C:\Users\user2\node_modules
C:\Users\node_modules
C:\node_modules

要解决此问题,请移动到与 node_modules 共享父目录的目录的子目录。文件夹,或使用 -g 全局安装模块标志。

关于node.js - NPM require ('tar' ) 找不到模块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19427480/

相关文章:

node.js - Azure 使用 REST api 和托管标识创建 blob 容器 - 403 错误

javascript - 可以在 Travis 启动的构建上运行 bower 和 npm 吗?

javascript - 为什么正确读取请求,服务器响应却错误?

node.js - Socket.IO连接错误

node.js - 无法以 express 方式发布到服务器

node.js - Windows10 - fatal error : Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

npm - 如何修复 Npm 缺少对等依赖项

javascript - 如何读取SSL数据?

javascript - Bluebird 在非 Node 式回调上的 promise

javascript - Node.js:变量范围在 Electron 和非 Electron 脚本中的行为不同