简体   繁体   English

webpack-找不到模块:错误:无法解析'jquery'

[英]webpack - Module not found: Error: Can't resolve 'jquery'

I'm using Sails 1 with webpack and when I attempt to import jquery from my main js file, I get this error yelling that it can't resolve jquery. 我正在将Sails 1与webpack一起使用,当我尝试从主js文件导入jquery时,我大喊这个错误,无法解决jquery。

webpack.config.js: webpack.config.js:

var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');

module.exports.webpack = {

    devtool: 'source-map',
    entry: {
        'admin': './assets/admin/js/admin.js'
    },
    output: {
        filename: 'js/[name].bundle.js',
        path: path.resolve(__dirname, '..', '.tmp', 'public')
    },
    resolve: {
        modules: [
            path.join(__dirname, "js"), "node_modules"
        ]
    },
    module: {
        // Extract less files
        rules: [{
            test: /\.css$/,
            loader: ExtractTextPlugin.extract({ use: 'css-loader' })
        }, {
            test: /\.less$/,
            loader: ExtractTextPlugin.extract({ use: 'css-loader!less-loader' })
        }, {
            test: /\.js$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            options: { 
                presets: [ 
                    [ 'es2015', { modules: false } ] 
                ] 
            }
        }]
    },
    plugins: [

        new webpack.ProvidePlugin({
            $: 'jquery',
            jQuery: 'jquery'
        }),
        // This plugin extracts CSS that was imported into .js files, and bundles
        // it into separate .css files.  The filename is based on the name of the
        // .js file that the CSS was imported into.
        new ExtractTextPlugin('css/[name].bundle.css'),

        // This plugin cleans out your .tmp/public folder before lifting.
        new CleanWebpackPlugin(['public'], {
            root: path.resolve(__dirname, '..', '.tmp'),
            verbose: true,
            dry: false
        }),

        // This plugin copies the `images` and `fonts` folders into
        // the .tmp/public folder.  You can add any other static asset
        // folders to this list and they'll be copied as well.
        new CopyWebpackPlugin([{
            from: './assets/images',
            to: path.resolve(__dirname, '..', '.tmp', 'public', 'images')
        }])
    ]
};

and in my assets/admin/js/admin.js I only have 在我的资产/admin/js/admin.js中,我只有

import 'jquery';

jquery is on my package json and it shows up under my node_modules packages with the name jquery . jQuery在我的包json上,并显示在我的node_modules包下,名称为jquery

Another weird thing is that if I change jquery and attempt to import angular , it works perfectly, so I don't think it's a node_modules directory issue or something like that. 另一个奇怪的是,如果我改变jQuery和尝试导入的角度 ,它完美的作品 ,所以我不认为这是一个node_modules目录问题,或者类似的东西。

A different issue brought me here. 一个不同的问题把我带到了这里。 For future visitors coming from Google, try running: 对于将来来自Google的访问者,请尝试运行:

webpack --display-error-details

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过webpack错误导入jquery - 找不到模块:无法解析jquery - importing jquery through webpack error - module not found: can't resolve jquery 找不到模块:错误:无法解析“ @ cycle / run” webpack 2.2.1 - Module not found: Error: Can't resolve '@cycle/run' webpack 2.2.1 webpack:找不到模块:错误:无法解析(使用相对路径) - webpack: Module not found: Error: Can't resolve (with relative path) Webpack:找不到模块:错误:无法解析“./containers” - Webpack: Module not found: Error: Can't resolve './containers' Webpack“找不到模块:错误:无法解析'./src/'” - Webpack "Module not found: Error: Can't resolve './src/'" Webpack:移动 webpack/react 文件的位置后,npm start “Module not found: Error: Can't resolve ...” - Webpack: npm start "Module not found: Error: Can't resolve ..." after moving location for webpack / react files 未找到汇总模块:错误:无法解析“jquery” - Rollup Module not found: Error: Can't resolve 'jquery' 多个./main.js中的错误。 找不到模块:错误:无法解析'/ home / user / workspace / webpack' - ERROR in multi ./main.js . Module not found: Error: Can't resolve '/home/user/workspace/webpack' 找不到主模块中的 WEBPACK5 错误:错误:无法解析“./src” - WEBPACK5 ERROR in main Module not found: Error: Can't resolve './src' Webpack css-loader:“未找到模块:错误:无法在...中解析'main.css'” - Webpack css-loader: “Module not found: Error: Can't resolve 'main.css' in …”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM