Cannot find module in Electron(在 Electron 中找不到模块)
问题描述
我目前正在与 Babylon 合作开发 Electron.我找到了 这个 repo,我基本上将它用作我自己项目的样板.在我尝试添加 jquery.pep.js 以满足其他需求之前,一切都运行良好.我一直犯这个错误:
I am currently working on Electron with Babylon. I found this repo which I basically used as a boilerplate for my own project. Everything was working well until I tried to add jquery.pep.js for other needs. I keep on having this mistake :
未捕获的错误:找不到模块jquery.pep.js"
Uncaught Error: Cannot find module 'jquery.pep.js'
我使用npm i -S jquery"和npm i -S jquery.pep.js"安装了这两个库.为了使 jquery 正常工作,我在 index.html 的头部添加了这个脚本
I installed both libraries with "npm i -S jquery" and "npm i -S jquery.pep.js". In order to make jquery works, I added this script in the head of my index.html
<script> delete window.module; </script>
我的 main.js 顶部的这一行:
and this line in the top of my main.js :
window.$ = window.jQuery = require('jquery');
现在,jquery 工作正常,但由于某些原因,仍然找不到 jquery.pep.js 模块.我尝试使用'require'但我有同样的错误
Now, jquery is working fine but for some reasons, jquery.pep.js module still can't be found. I tried to use 'require' but I have the same error
main.js
window.$ = window.jQuery = require('jquery');
var pep = require('jquery.pep.js');
项目结构
CSS/
图片/
js/
-- main.js
节点模块/
index.html
index.js
包.json
渲染器.js
Project structure
css/
img/
js/
-- main.js
node_modules/
index.html
index.js
package.json
renderer.js
推荐答案
您正在请求某些内容,但节点无法找到它.你可以阅读这篇关于在 node 中需要模块,这很简单地解释了它.引用:
You are requesting something and node is not able to find it. You can read this dedicated article on requiring modules in node, which explains it quite simply. Quoting:
当我们需要一个find-me"模块时,没有指定路径:
When we require a 'find-me' module, without specifying a path:
require('find-me');
Node 将在所有指定的路径中查找 find-me.js
module.paths
— 按顺序.
Node will look for find-me.js
in all the paths specified by
module.paths
— in order.
$ node
> module.paths
[ '/Users/samer/learn-node/repl/node_modules',
'/Users/samer/learn-node/node_modules',
'/Users/samer/node_modules',
'/Users/node_modules',
'/node_modules',
'/Users/samer/.node_modules',
'/Users/samer/.node_libraries',
'/usr/local/Cellar/node/7.7.1/lib/node' ]
paths 列表基本上是 node_modules 目录下的列表从当前目录到根目录的每个目录.它还包括一些不推荐使用的遗留目录.
The paths list is basically a list of node_modules directories under every directory from the current directory to the root directory. It also includes a few legacy directories whose use is not recommended.
如果 Node 在这些路径中都找不到 find-me.js
,它会抛出一个找不到模块错误."
If Node can’t find find-me.js
in any of these paths, it will throw a
"cannot find module error."
~/learn-node $ node
> require('find-me')
Error: Cannot find module 'find-me'
at Function.Module._resolveFilename (module.js:470:15)
at Function.Module._load (module.js:418:25)
at Module.require (module.js:498:17)
at require (internal/module.js:20:19)
at repl:1:1
at ContextifyScript.Script.runInThisContext (vm.js:23:33)
at REPLServer.defaultEval (repl.js:336:29)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.onLine (repl.js:533:10)
确保您的模块安装在节点称为 module.paths
的某个位置,或通过提供绝对路径来引用该文件.
Make sure you have your module installed somewhere in what node knows as module.paths
, or reference the file by providing absolute path.
这篇关于在 Electron 中找不到模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Electron 中找不到模块
基础教程推荐
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 动态更新多个选择框 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01