在 Electron / Atom 中找不到模块 Shell

Module not found in Electron / Atom Shell

我是 npm、node 和 Electron 的新手。

我的文件夹看起来像:

-package.json
-index.html
-main.js
-js/myStuff.js
-node_modules

在文件 myStuff.js 中我有 var chokidar = require('chokidar'); 但它显示 module not found 错误。

index.html 中,我像往常一样在脚本标签中包含了 myFile.js

我读过节点如何寻找模块。但这无济于事,因为它应该找到它,因为它在所有父目录中查找 node_modules 文件夹,然后在其中查找 chokidar 文件夹,然后在其中查找 index.js 文件,这是那里。

我做错了什么?

现在可以用了,但我不知道为什么..

与其他节点应用程序相比,Electron 不会自动将您的 NODE_PATH 设置为全局(即 /usr/bin)或本地(例如 node_modulesfolders。所以需要手动导出:

NODE_PATH=/path/to/node_modules electron my_app