2

我正在尝试在未连接到网络的 LAN 上安装 node.js。我已经安装了 node.js 没有任何问题,但似乎 npm 想上网,

  http GET https://registry.npmjs.org/moment 
所以我无法安装我需要的模块。

这是生成的 npm-debug 文件:

 
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install',
1 verbose cli   'moment',
1 verbose cli   '-g' ]
2 info using npm@1.1.69
3 info using node@v0.8.16
4 verbose node symlink C:\Program Files\nodejs\\node.exe
5 verbose read json C:\Documents and Settings\User.PALS-DADS\Application Data\npm\package.json
6 verbose read json C:\Documents and Settings\User.PALS-DADS\Application Data\npm\package.json
7 verbose cache add [ 'moment', null ]
8 silly cache add name=undefined spec="moment" args=["moment",null]
9 verbose parsed url { pathname: 'moment', path: 'moment', href: 'moment' }
10 silly lockFile b56def36-moment moment
11 verbose lock moment C:\Documents and Settings\User.PALS-DADS\Application Data\npm-cache\b56def36-moment.lock
12 silly lockFile b56def36-moment moment
13 verbose addNamed [ 'moment', '' ]
14 verbose addNamed [ null, '' ]
15 silly lockFile 42aa250a-moment moment@
16 verbose lock moment@ C:\Documents and Settings\User.PALS-DADS\Application Data\npm-cache\42aa250a-moment.lock
17 silly addNameRange { name: 'moment', range: '', hasData: false }
18 verbose url raw moment
19 verbose url resolving [ 'https://registry.npmjs.org/', './moment' ]
20 verbose url resolved https://registry.npmjs.org/moment
21 info trying registry request attempt 1 at 16:47:42
22 http GET https://registry.npmjs.org/moment
23 info retry will retry, error on last attempt: Error: getaddrinfo ENOENT
24 info trying registry request attempt 2 at 16:47:52
25 http GET https://registry.npmjs.org/moment
26 info retry will retry, error on last attempt: Error: getaddrinfo ENOENT
27 info trying registry request attempt 3 at 16:48:52
28 http GET https://registry.npmjs.org/moment
29 silly lockFile 42aa250a-moment moment@
30 error Error: getaddrinfo ENOENT
30 error     at errnoException (dns.js:31:11)
30 error     at Object.onanswer [as oncomplete] (dns.js:123:16)
31 error If you need help, you may report this log at:
31 error     
31 error or email it to:
31 error     
32 error System Windows_NT 5.1.2600
33 error command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "moment" "-g"
34 error cwd C:\Documents and Settings\User.PALS-DADS\Desktop
35 error node -v v0.8.16
36 error npm -v 1.1.69
37 error syscall getaddrinfo
38 error code ENOTFOUND
39 error errno ENOTFOUND
40 verbose exit [ 1, true ]
 

如何在不连接网络的情况下安装模块?

谢谢

4

1 回答 1

4

如果您查看文档,您会发现您可以通过简单地将文件系统路径或 URL 传递给包含您要安装的包的tarball来安装包。

npm install http://server.on.lan/moment.tgz

当然,如果有问题的包指定了任何依赖项,npm 将尝试从 Web 获取它们。moment 没有任何内容,因此您应该可以下载 tarball 并安装它。

然而,如果你想安装其他有依赖关系的包,你最好在你的局域网上设置一个 npm 注册表镜像。

于 2012-12-27T17:35:19.437 回答