我正在设置NODE_PATH
on Linux来指向我的外部模块,它运行良好。
相同的Bash脚本可以通过Git-bash在Windows下运行,并且运行良好。但是,NODE_PATH
在Windows节点上无法识别:“找不到模块'dcs'”。
预先设置NODE_DEBUG=module
会输出以下调试信息:
MODULE 2992: Module._load REQUEST dcs parent: .
MODULE 2992: looking for "dcs" in ["C:\\Users\\cca\\Desktop\\myproject\\servers\\node_modules","C:\\Users\\cca\\Desktop\\myproject\\node_modules","C:\\Users\\cca\\Desktop\\node_modules","C:\\Users\\cca\\node_modules","C:\\Users\\node_modules","C:\\node_modules","/c/Users/cca/Desktop/myproject/scada.js/lib::/c/Users/cca/Desktop/myproject/scada.js/lib/dcs/node_modules:/c/Users/cca/Desktop/myproject/scada.js/lib/dcs/services/couch-dcs/node_modules:/c/Users/cca/Desktop/myproject/scada.js/lib/dcs/services/dcs-proxy/socket-io/node_modules:/c/Users/cca/Desktop/myproject/scada.js/node_modules:","C:\\Users\\cca\\.node_modules","C:\\Users\\cca\\.node_libraries","C:\\Program Files\\lib\\node"]
Failed at: io-server.ls
Error: Cannot find module 'dcs'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\cca\Desktop\myproject\servers\io-server.ls:6:10)
at Module._compile (module.js:570:32)
at Module._compile (C:\Users\cca\AppData\Roaming\npm\node_modules\livescript\node_modules\source-map-support\source-map-support.js:510:25)
at Object.LiveScript.run (C:\Users\cca\AppData\Roaming\npm\node_modules\livescript\lib\node.js:33:19)
at compileScript (C:\Users\cca\AppData\Roaming\npm\node_modules\livescript\lib\command.js:192:31)
at C:\Users\cca\AppData\Roaming\npm\node_modules\livescript\lib\command.js:118:11
我注意到“在...中查找” dcs”行输出了一个数组,该数组具有多个路径以及脚本中的NODE_PATH
我export
。但是,它的语法与其他路径不同(原始文件为C:\\some\\path
,外部文件为/c/some/path
)。
如何在Windows上正确设置NODE_PATH
,以便可以require
使用模块而不使用其完整路径?