webpack无法安装style-loader问题(Vue.js 2)
P粉864872812
P粉864872812 2023-07-29 09:49:43
[Vue.js讨论组]
<p>我需要安装style-loader以便能够加载import 'bootstrap-icons/font/bootstrap-icons.css'。然而,当我输入npm install style-loader时,出现以下错误:</p> <pre class="brush:php;toolbar:false;">npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: undefined@undefined npm ERR! Found: webpack@4.46.0 npm ERR! node_modules/webpack npm ERR! dev webpack@"^4.41.2" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer webpack@"^5.0.0" from style-loader@3.3.3 npm ERR! node_modules/style-loader npm ERR! style-loader@"*" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force, or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution. npm ERR! npm ERR! See /Users/jessiechen/.npm/eresolve-report.txt for a full report. npm ERR! A complete log of this run can be found in: npm ERR! /Users/jessiechen/.npm/_logs/2023-07-16T00_15_26_704Z-debug-0.log</pre> <p>这是我的webpack.config.js文件。</p> <pre class="brush:php;toolbar:false;">var HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { mode: 'development', resolve: { extensions: ['.js', '.jsx','.vue', '.css'], modules: [ 'node_modules' ] }, module: { rules: [ { test: /.vue?$/, exclude: /(node_modules)/, use: 'vue-loader' }, { test: /.js?$/, exclude: /(node_modules)/, use: 'babel-loader' }, { test: /.css$/i, use: [{loader:'style-loader'}, {loader: 'css-loader'}], }, { test: /.(png|jpe?g|gif)$/i, use: [ { loader: 'file-loader', options: { esModule: false } }, ], }, ] }, plugins: [new HtmlWebpackPlugin({ template: './src/index.html' })], devServer: { historyApiFallback: true }, externals: { // global app config object config: JSON.stringify({ apiUrl: 'http://localhost:4000' }) }, }</pre> <p>这是我的package.json文件:</p> <pre class="brush:php;toolbar:false;">{ "scripts": { "start": "webpack-dev-server --open", "build": "webpack --mode production" }, "dependencies": { "@babel/runtime": "^7.22.6", "bootstrap": "^5.3.0", "bootstrap-icons": "^1.10.5", "regenerator-runtime": "^0.13.11", "vee-validate": "^2.2.8", "vue": "^2.6.10", "vue-router": "^3.1.3", "vuex": "^3.1.2", "xlsx": "^0.18.5" }, "devDependencies": { "@babel/plugin-transform-runtime": "^7.22.7", "babel-core": "^6.26.0", "babel-loader": "^7.1.5", "babel-preset-env": "^1.6.1", "babel-preset-stage-0": "^6.24.1", "babel-preset-vue": "^2.0.2", "css-loader": "^3.3.2", "file-loader": "^6.2.0", "html-webpack-plugin": "^3.2.0", "path": "^0.12.7", "vue-loader": "^14.2.3", "vue-template-compiler": "^2.6.10", "webpack": "^4.41.2", "webpack-cli": "^3.3.10", "webpack-dev-server": "^3.9.0" } }</pre> <p>我已经尝试删除package.lock.json文件并重新安装所有的包,但是每次我尝试安装style-loader时都会出现错误。</p>
P粉864872812
P粉864872812

全部回复(1)
P粉133321839

运行npm install style-loader --legacy-peer-deps。如果你能够熟悉并信任工具发出的错误消息,这将对你很有帮助。

但你也需要更新你的依赖项(检查npm outdated)。你有各种不兼容的包版本。对于任何有重大变化的包(版本号最左边的数字变化),你可能需要查看该包的变更日志,通常可以在其GitHub仓库或Releases标签中找到。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号