当前在线人工客服
天达云-技术
QQ:1324027256
天达云-技术
QQ:1902643386
天达云-售前
QQ:1650874901
天达云-售前
QQ:2207995833
天达云-合作
QQ:1984186903
天达云微信小程序
400-837-6568

Electron —— Cannot find module ‘jquery.min.js’
更新:HHH   时间:2023-1-7


在页面中使用如下代码引入jquery:

<script>
    window.$ = window.jQuery = require('node_modules/jquery/dist/jquery.min.js');
</script>

运行时报错:
Uncaught Error: Cannot find module 'node_modules/jquery/dist/jquery.min.js'
 
这个错误一看就是跟路径有关,项目中引入jquery的index.html页面与node_modules的关系如下:

 
按道理index.html与node_modules在同一个目录下,上面代码的引入方式应该是可以的,可是事实上electron就是没有找到正确的node_modules目录。
 
在引入jquery的地方增加“./”,其中“.”表示当前目录,即代码改为如下:

<script>
    window.$ = window.jQuery = require('./node_modules/jquery/dist/jquery.min.js');
</script>
返回web开发教程...