gpt4 book ai didi

node.js - 有没有办法找到 Node 从哪里加载模块?

转载 作者:搜寻专家 更新时间:2023-11-01 00:43:25 25 4
gpt4 key购买 nike

有没有办法在模块被要求后找到模块的路径?

所以我的问题是 - 我启动 Node repl,require('stylus') 它从某个地方加载它。

我做了 npm cache cleanrm -rf node_modulesnpm uninstall -g stylus 等,但它仍然成功地从某处。

最佳答案

使用 require.resolve('stylus')。这将为您提供模块的路径,但不会导入它。

所以在 REPL 中。

> require.resolve('stylus');

如果您需要的话,您还可以从模块内部引用 module.filename

关于node.js - 有没有办法找到 Node 从哪里加载模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26896602/

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