gpt4 book ai didi

node.js - 在 Node REPL 中使用第 3 方包

转载 作者:太空宇宙 更新时间:2023-11-03 22:16:30 25 4
gpt4 key购买 nike

我正在尝试在 Node 中使用 d3(并且之前以某种方式成功地完成了?)。所以我就这么做了

npm install -g d3

效果很好。让我们检查一下:

$ npm list -g d3
/usr/local/lib
└── d3@3.4.13
太棒了。让我们确保我的包裹正确:

$ grep name /usr/local/lib/node_modules/d3/package.json 
"name": "d3",
太棒了。所以尝试要求它:

$ node

var d3 = require('d3');
Error: Cannot find module 'd3'
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:10
at REPLServer.self.eval (repl.js:110:21)
at repl.js:249:20
at REPLServer.self.eval (repl.js:122:7)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)

不!给出了什么?

最佳答案

默认情况下,您不能 require() 全局安装模块(无需使用特殊的环境变量等)。如果您执行 npm install d3,则 require('d3') 应该在当前工作目录中的 REPL 中运行。

关于node.js - 在 Node REPL 中使用第 3 方包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26940893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com