简体   繁体   English

Electron:找不到模块 jQuery

[英]Electron : can not find module jQuery

I am trying to use jQuery and bootstrap in my electron project我正在尝试在我的 electron 项目中使用 jQuery 和引导程序

I want to use them like:我想像这样使用它们:

window.$ = window.jQuery = require('jquery') 
var bootstrap = require('bootstrap') 

each of these lines give me an error:这些行中的每一行都给我一个错误:

Uncaught Error: Cannot find module 'jquery'

or或者

Uncaught Error: Cannot find module 'bootstrap'

But when I check in my node modules directory I can see both bootstrap and jquery folders但是当我检查我的节点模块目录时,我可以看到 bootstrap 和 jquery 文件夹

Also I can find this path in environment variable and also in node (module.paths)我也可以在环境变量和节点(module.paths)中找到这个路径

I tried any kind of installation like:我尝试了任何类型的安装,例如:

npm install jquery --save
npm install jquery --save-dev
npm install jquery -g 

Still I am getting this error and I don't know why我仍然收到此错误,我不知道为什么

When I use nodejs in command line like this:当我在这样的命令行中使用 nodejs 时:

>>>node
>require('bootstrap')
Thrown:
{ Error: Cannot find module 'popper.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at C:\Users\Majidi\node_modules\bootstrap\dist\js\bootstrap.js:7:102 code: 'MODULE_NOT_FOUND' }

I'm not sure why your module require statement isn't working for some reason but the other alternative to adding Bootstrap, Popper, and jQuery through Node.js modules is just using the CDN in the HTML file.我不确定为什么您的模块 require 语句由于某种原因不起作用,但通过 Node.js 模块添加 Bootstrap、Popper 和 jQuery 的另一种替代方法只是使用 Z4C4AD5FCA2E7A3F74DBB1CED00381Z 文件中的 CDN。

This should work fine: (make sure to include in the <head> tag of your renderer.html file)这应该可以正常工作:(确保包含在您的 renderer.html 文件的<head>标记中)

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

These snippets are from theBootstrap getting started page.这些片段来自Bootstrap 入门页面。

Also make sure to put the <script> tags for your own JS files AFTER the snipped above to properly use jQuery.还要确保在上面的剪辑之后为您自己的 JS 文件添加<script>标签,以正确使用jQuery

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

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