简体   繁体   English

在Electron中找不到模块

[英]Cannot find module in Electron

I am currently working on Electron with Babylon. 我目前正在研究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. 在我尝试添加jquery.pep.js以满足其他需求之前,一切运行良好。 I keep on having this mistake : 我继续犯这个错误:

Uncaught Error: Cannot find module 'jquery.pep.js' 未捕获错误:找不到模块'jquery.pep.js'

I installed both libraries with "npm i -S jquery" and "npm i -S jquery.pep.js". 我用“npm i -S jquery”和“npm i -S jquery.pep.js”安装了两个库。 In order to make jquery works, I added this script in the head of my index.html 为了使jquery工作,我在index.html的头部添加了这个脚本

<script> delete window.module; </script>

and this line in the top of my main.js : 这行在main.js的顶部:

window.$ = window.jQuery = require('jquery');

Now, jquery is working fine but for some reasons, jquery.pep.js module still can't be found. 现在,jquery工作正常,但由于某些原因,仍然无法找到jquery.pep.js模块。 I tried to use 'require' but I have the same error 我尝试使用'require',但我有同样的错误

main.js main.js

window.$ = window.jQuery = require('jquery'); 
var pep = require('jquery.pep.js');

Project structure 项目结构

css/ CSS /
img/ IMG /
js/ JS /
-- main.js - main.js
node_modules/ node_modules /
index.html 的index.html
index.js index.js
package.json 的package.json
renderer.js renderer.js

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: 引用:

When we require a 'find-me' module, without specifying a path: 当我们需要'find-me'模块时,不指定路径:

require('find-me');

Node will look for find-me.js in all the paths specified by module.paths — in order. Node将按find-me.jsmodule.paths指定的所有路径中find-me.js

 $ 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' ] 

The paths list is basically a list of node_modules directories under every directory from the current directory to the root directory. 路径列表基本上是从当前目录到根目录的每个目录下的node_modules目录列表。 It also includes a few legacy directories whose use is not recommended. 它还包括一些不推荐使用的旧目录。

If Node can't find find-me.js in any of these paths, it will throw a “cannot find module error.” 如果Node无法在任何这些路径中找到find-me.js ,它将抛出“无法找到模块错误”。

 ~/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) 

Make sure you have your module installed somewhere in what node knows as module.paths , or reference the file by providing absolute path. 确保将模块安装在某个节点知道为module.paths某个位置,或通过提供绝对路径引用该文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM