jQuery   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了安装jQuery会导致webpack错误大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_673_0@
@H_673_0@
我npm安装了jQuery,现在看到一堆模块未找到:错误:无法解决错误.知道根本问题可能是什么和解决方案?

ERROR in ./node_modules/jquery/lib/node-jquery.js
Module not found: Error: Can't resolve 'jsdom'...

ERROR in ./node_modules/jquery/lib/node-jquery.js
Module not found: Error: Can't resolve 'xmlhttprequest'...

ERROR in ./node_modules/jquery/lib/node-jquery.js
Module not found: Error: Can't resolve 'LOCATIOn'...

ERROR in ./node_modules/jquery/lib/node-jquery.js
Module not found: Error: Can't resolve 'navigator'...

我很确定这是在搜索错误之后与webpack 2有关,但是所提出的解决方案都没有解决错误.

我见过但不起作用的一个解决方案是在我的webpack配置中添加以下内容

plugins: [
  new webpack.ProvidePlugin({
      $: "jquery",jQuery: "jquery"
  })
],

这是我的index.html:

<html>
  <head>
    <Meta charset="utf-8">
    <title>title</title>
  </head>
  <body>
    <div id="fb-root"></div>
    <div id="app"></div>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/latest/css/bootstrap.min.css">
    <script src="common.js"></script>
    <script src="bundle.js" type="text/javascript"></script>
  </body>
</html>

这是我的webpack.config.js:

var webpack = require('webpack');
var path = require('path');

var BUILD_DIR = path.resolve(__dirname,'public');
var APP_DIR = path.resolve(__dirname,'src','js');

var node_dir = __dirname + '/node_modules';

var config = {
	entry: {
	  app: APP_DIR + '/index.js',common: ["jquery"],},output: {
		path: BUILD_DIR,filename: 'bundle.js'
	},resolve: {
		// This is so that you don't have to write the file extension while imporTing it.
		// Instead of import HomeComponent from './HomeComponent.jsx'
		// you can do import HomeComponent from './HomeComponent'
		extensions: ['.js','.jsx','.json','*'],alias: {
      'jquery': node_dir + '/jQuery/src/wrapper.js',externals: {
    jquery: 'jQuery'
  },plugins: [
    new webpack.optimize.CommonsChunkPlugin({
      name: "common",filename: "common.js",minChunks: Infinity,}),new webpack.ProvidePlugin({
      $: "jquery",jQuery: "jquery",jquery: "jquery","window.jQuery": "jquery",],module: {
    loaders : [
			{
				test : /\.jsx?/,include : APP_DIR,exclude: /node_modules/,loader : 'babel-loader'
			}
		],};

module.exports = config;

这是错误

安装jQuery会导致webpack错误

解决方法

您是否安装了 jQuery npm包而不是 jquery包?使用已弃用的’jQuery’我有同样的错误.当我删除’jQuery’并安装’jquery’时,错误就消失了.
@H_673_0@

大佬总结

以上是大佬教程为你收集整理的安装jQuery会导致webpack错误全部内容,希望文章能够帮你解决安装jQuery会导致webpack错误所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:jquerywebpack安装导致错误
猜你在找的jQuery相关文章
其他相关热搜词更多
phpJavaPython程序员load如何string使用参数jquery开发安装listlinuxiosandroid工具javascriptcap