2017-07-07 5 views
0

npmにjQueryがインストールされ、Module not found: Error: Can't resolve...というエラーが表示されています。根本的な問題と解決策の考え方jQueryをインストールするとwebpackエラーが発生する

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

 
module.exports = config;

そして、ここではエラーです:あなたはjQuery NPMパッケージの代わりに、jqueryパッケージをenter image description here

+0

このポストはまだ見ましたか? https://stackoverflow.com/questions/44084544/jquery-with-webpack-2 –

+0

残念ながら、エラーはまだ存在します。 – chewchew

答えて

6

インストールしましたか?私は、廃止された 'jQuery'を使って同じエラーが発生しました。 「jQuery」を削除して「jquery」をインストールすると、エラーは消えてしまいました。

関連する問題