在页面中使用以下代码引入jquery:html
<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的地方增长“./”,其中“.”表示当前目录,即代码改成以下:node
<script> window.$ = window.jQuery = require('./node_modules/jquery/dist/jquery.min.js'); </script>