webpack中can't resolve style-loader

发布于 2022-09-06 05:44:19 字数 1942 浏览 24 评论 0

webpack can't resolve style-loader 配置如下,求解

package.json配置:

{
  "name": "webpack-one",
  "version": "1.0.0",
  "description": "webpack practice for first time",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack-dev-server --progress --color --hot --inline"
  },
  "author": "Li",
  "license": "ISC",
  "devDependencies": {
    "babel": "^6.23.0",
    "babel-core": "^6.26.0",
    "babel-loader": "^7.1.2",
    "css-loader": "^0.28.7",
    "file-loader": "^1.1.5",
    "style-loader": "^0.19.0",
    "stylus": "^0.54.5",
    "stylus-loader": "^3.0.1",
    "url-loader": "^0.6.2",
    "webpack": "^3.8.1"
  },
  "dependencies": {
    "webpack-dev-server": "^2.9.4"
  }
}

webpack.config.js:

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

module.exports = {
  entry: {
    admin: __dirname + '/admin/main.js',
    consumer: __dirname + '/consumer/main.js'
  },
  output : {
    path: path.join(__dirname + '/dist'),
    publicPath: '/dist/',
    filename: '[name].[hash].bundle.js'
  },
  module: {
    rules:[{
      test: /\.js$/,
      use: [
        {loader: 'babel-loader'}
      ]
    },{
      test: /\.css$/,
      use: [
        {loader: 'style-loader'},
        {loader: 'css-loader'}
      ]
    }]
  }
};

main.js:

require('./index.css')

document.getElementById('content').innerHTML = 'This is Admin Page!!!!';

提示:
ERROR in ./admin/main.js
Module not found: Error: Can't resolve 'style-loader' in '/Users/lijialong/coding/webpack-sample'
@ ./admin/main.js 1:0-22
@ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./admin/main.js

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九局 2022-09-13 05:44:19

是不是'style-loader' 没有安装好,使用npm install 或者 yarn重新安装试试。

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文