webpack Can't resolve 'style'

房东的猫 提交于 2019-12-08 15:44:54

问题


I was trying to follow the simple Getting Started from (http://webpack.github.io/docs/tutorials/getting-started/). And I am getting this error when I try to load style.css.

ERROR in ./entry.js Module not found: Error: Can't resolve 'style' in 'Path to project in my computer' BREAKING CHANGE: It's no longer allowed to omit the '-loader' suffix when using loaders. You need to specify 'style-loader' instead of 'style'. @ ./entry.js 1:0-22

Any ideas ?

I installed css-loader and style-loader locally using mpm as explained in tutorial. npm install css-loader style-loader

I see node-modules folder created after the installation.


回答1:


For webpack version >=2.0

Update webpack.config.js

module.exports = {
    entry: "./entry.js",
    output: {
        path: __dirname,
        filename: "bundle.js"
    },
    module: {
        loaders: [
            { test: /\.css$/, loader: "style-loader!css-loader" }
        ]
    }
};

Use { test: /.css$/, loader: "style-loader!css-loader" } instead of { test: /.css$/, loader: "style!css!" }




回答2:


Tried 'Use { test: /.css$/, loader: "style-loader!css-loader" } instead of { test: /.css$/, loader: "style!css!" }' as above but failed, below config works for me:

{
    test:/\.css$/,
    loader:'style-loader!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]'
}


来源:https://stackoverflow.com/questions/42196583/webpack-cant-resolve-style

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!