打包webpack时出错:
ERROR in ./node_modules/jquery/lib/node-jquery.js
npm run dev
报错提示:
ERROR in ./node_modules/jquery/lib/node-jquery.js
Module not found: Error: Can't resolve 'jsdom' in 'E:\Users\Administrator\Desktop\webpack笔记\node_modules\jquery\lib'
@ ./node_modules/jquery/lib/node-jquery.js 5:13-29
@ ./src/index.js
ERROR in ./node_modules/jquery/lib/node-jquery.js
Module not found: Error: Can't resolve 'location' in 'E:\Users\Administrator\Desktop\webpack笔记\node_modules\jquery\lib'
@ ./node_modules/jquery/lib/node-jquery.js 13:24-43
@ ./src/index.js
ERROR in ./node_modules/jquery/lib/node-jquery.js
Module not found: Error: Can't resolve 'navigator' in 'E:\Users\Administrator\Desktop\webpack笔记\node_modules\jquery\lib'
@ ./node_modules/jquery/lib/node-jquery.js 17:25-45
@ ./src/index.js
ERROR in ./node_modules/jquery/lib/node-jquery.js
Module not found: Error: Can't resolve 'xmlhttprequest' in 'E:\Users\Administrator\Desktop\webpack笔记\node_modules\jquery\lib'
@ ./node_modules/jquery/lib/node-jquery.js 8:28-53
@ ./src/index.js
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! module-webpack@1.0.0 dev: `webpack`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the module-webpack@1.0.0 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2020-05-13T16_12_47_307Z-debug.log
解决:
-
查看默认打包入口
index.js
是否在src
文件夹中,(该src文件夹包含index.html及index.js) -
在项目目录终端安装jQuery时,输入命令:
npm install jquery -S
,注意此时要安装jquery
,而不是jQuery
,不然同样会报错
打包成功的结果: