- 90
- 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
- 共 0 条
- 全部回答
-
水木皿 普通会员 1楼
The
style-loaderis a part of the CSS modules ecosystem, which webpack uses to automatically apply styles to your project's HTML files. If you are having trouble resolving thestyle-loaderin your webpack configuration, there could be several reasons:- Missing configuration: Make sure you have correctly installed and configured the
style-loaderin your webpack configuration file, either by including it in theresolveconfiguration or by adding it to themodulesection of thewebpack.config.jsfile.
Here's an example of how you might include the
style-loaderin yourwebpack.config.jsfile: ```javascript const path = require('path');module.exports = { // ... resolve: { extensions: ['.js', '.jsx', '.css', '.less'], alias: { // Add the styles directory here, if necessary 'style': path.resolve(__dirname, 'styles'), }, }, module: { rules: [ { test: /.css$/, use: [ { loader: 'style-loader', }, ], }, ], }, };
`` In this example, we are specifying that thestyledirectory in thestylesdirectory is the alias for thestyle-loader, so we can use thestyle-loaderinstead of thestyle-loader` in our project's modules.-
Missing
style-loaderin your project: Ensure that thestyle-loaderis available in your project'snode_modulesdirectory. Make sure you have added the following line to yourpackage.jsonfile:json "styles": "node_modules/your-style-loader/dist/your-style-loader.js"Replaceyour-style-loaderwith the name of thestyle-loaderthat you installed in your project anddist/with the appropriate path for the output directory of yourstyle-loader. -
Webpack CLI configuration issue: If you are using the
webpack CLIinstead of webpack itself, ensure that you have correctly configured thestyle-loaderin your CLI'sstyle-loaderconfiguration. Here's an example: ```bash
Add the following to your
style-loaderconfiguration in the CLI'sstyle-loadermodule:module.exports = { // ... use: [ { loader: 'style-loader', options: { sourceMap: true, }, }, ], };
`` This configuration tells webpack to use thestyle-loaderwith source maps, which allows you to map the output of thestyle-loader` to a separate JavaScript file for debugging and performance purposes.- Webpack dependency tree issue: Ensure that you have installed the
style-loaderin the correct tree. Thestyle-loaderis a part of thecss-loaderand thecss-loaderis a part of thestyle-loaderand thestyle-loaderis also a part of thepostcss-loader. If you have installed thestyle-loaderin the wrong tree, it might not work correctly. In your webpack configuration, make sure that thestyle-loaderis installed in thenode_modulestree, which is the root of your project's modules. - Missing
style-loaderin your development environment: Make sure you have thestyle-loaderinstalled in your development environment, as it is not included in thebuildphase of webpack. If you are using a development environment like Node.js or a React project, you might need to install thestyle-loaderglobally using npm:bash npm install style-loaderOnce you have installed thestyle-loader, you should be able to use it in your webpack configuration without any issues.
- Missing configuration: Make sure you have correctly installed and configured the
- 扫一扫访问手机版
回答动态

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器更新之后。服务器里面有部分玩家要重新创建角色是怎么回事啊?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题函数计算不同地域的是不能用内网吧?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题ARMS可以创建多个应用嘛?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题在ARMS如何申请加入公测呀?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题前端小程序接入这个arms具体是如何接入监控的,这个init方法在哪里进行添加?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器刚到期,是不是就不能再导出存档了呢?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器的游戏版本不兼容 尝试更新怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器服务器升级以后 就链接不上了,怎么办?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器转移以后服务器进不去了,怎么解决?预计能赚取 0积分收益

- 神奇的四哥:发布了悬赏问题阿里云幻兽帕鲁服务器修改参数后游戏进入不了,是什么情况?预计能赚取 0积分收益
- 回到顶部
- 回到顶部
