根据@vendorname/functions
,我有一个模块npm list
在文件系统上不存在
$ npm ls @vendorname/functions
serverless-commerce@1.0.0 C:\Users\mikem\OneDrive\Documents\myapp\myapp
`-- (empty)
根据演示文件,它也不存在:
$ node
> require("@vendorname/functions")
{ Error: Cannot find module '@vendorname/functions'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
at Function.Module._load (internal/modules/cjs/loader.js:506:25)
at Module.require (internal/modules/cjs/loader.js:636:17)
at require (internal/modules/cjs/helpers.js:20:18) code: 'MODULE_NOT_FOUND' }
但是,我在使用该模块的父文件夹C:\Users\mikem\OneDrive\Documents\myapp\myapp
中有一块软件可以正常工作:
let vendornameFunctions = require("@vendorname/functions"),
log(`>>> MYSTERY FILE IS BEING IMPORTED ${JSON.dumps(vendornameFunctions, null, 2)}`);
返回:
>>> MYSTERY FILE IS BEING IMPORTED {
"events": {},
"queues": {},
"tables": {},
"html": {},
"json": {},
"css": {},
"js": {},
"text": {},
"xml": {}
}
我可以可靠地复制此行为。 如何确定从哪个磁盘上加载模块?
答案 0 :(得分:2)
您可以使用require.resolve
来获取模块的路径。
console.log(require.resolve("@vendorname/functions"));