我正在使用beaker笔记本并希望使用一些外部节点模块 - 但由于beaker不会将系统路径更改为当前活动文件的目录,因此我将尝试包含stream-filter
错误:
Error: Cannot find module 'stream-filter'
Error: Cannot find module 'stream-filter'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:286:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at eval (eval at processCode (/opt/homebrew-cask/Caskroom/beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/app.js:45:23), :5:14)
at processCode (/opt/homebrew-cask/Caskroom/beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/app.js:45:18)
at /opt/homebrew-cask/Caskroom/beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/app.js:32:28
at callbacks (/opt/homebrew-cask/Caskroom/beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/node_modules/express/lib/router/index.js:164:37)
at param (/opt/homebrew-cask/Caskroom/beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/node_modules/express/lib/router/index.js:138:11)
at pass (/opt/homebrew-cask/Caskroom/beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/node_modules/express/lib/router/index.js:145:5)
我想知道如何解决这个问题。尽管在同一目录中的process.chdir('/Users/akivalipshitz/Developer/Computational_Linguistics')
中安装了流过滤器,但我尝试node_modules
无济于事。
那么人们如何使用节点模块
答案 0 :(得分:0)
在您的情况下,节点代码被评估的上下文
/opt/homebrew-cask/Caskroom//beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/app.js
因此require()
在node_modules
文件夹中查找模块,然后沿父文件夹(see docs)递归递增。
一个解决方案(如果您只处理一个项目或在所有项目中经常使用此模块)将在那里安装您的模块:
cd /opt/homebrew-cask/Caskroom//beaker/1.4.2-1-ge55c059/Beaker.app/Contents/Resources/dist/config/plugins/eval/node/app/
npm install stream-filter
另一种(丑陋的)方法可能是在require()中构建一个长的相对路径。在你的情况下像:
require('../../../../../../../../../../../../Users/akivalipshitz/Developer/Computational_Linguistics');
这两种情况都意味着您的代码无法移植到另一个beaker实例。但是,至少在提出更好的解决方案之前,这可以帮助您进行原型设计。
答案 1 :(得分:0)