gpt4 book ai didi

vue.js - 使用 Vue 2 设置 Webpack 5 时出现 "Cannot find module ' vue/compiler-sfc'"

转载 作者:行者123 更新时间:2023-12-05 00:51:42 25 4
gpt4 key购买 nike

我正在尝试使用 Vue 2 设置 Webpack 5,以使用 ModuleFederation。但是,当我尝试启动服务器时,我遇到了以下错误:

[webpack-cli] Failed to load '/Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/webpack.config.js' config
[webpack-cli] Error: Cannot find module 'vue/compiler-sfc'
Require stack:
- /Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/node_modules/vue-loader/dist/index.js
- /Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/webpack.config.js
- /Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/node_modules/webpack-cli/lib/webpack-cli.js
- /Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/node_modules/webpack-cli/lib/bootstrap.js
- /Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/node_modules/webpack-cli/bin/cli.js
- /Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/node_modules/webpack-dev-server/bin/webpack-dev-server.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/node_modules/vue-loader/dist/index.js:8:24)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/node_modules/vue-loader/dist/index.js',
'/Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/webpack.config.js',
'/Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/node_modules/webpack-cli/lib/webpack-cli.js',
'/Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/node_modules/webpack-cli/lib/bootstrap.js',
'/Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/node_modules/webpack-cli/bin/cli.js',
'/Users/pottsiex5/Documents/Random Stuff/modulefed/hello-world/node_modules/webpack-dev-server/bin/webpack-dev-server.js'
]
}

我怀疑这与冲突版本有关,因为我看到了更新到 Vue 3 以解决此问题的建议,但这不是我的选择。是否可以使用 Vue 2 运行 Webpack 5?我只需要安装某个软件包的特定版本吗?这是我的 package.json:

{
"name": "hello-world",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"lint": "vue-cli-service lint",
"build": "webpack --mode production",
"start": "webpack-dev-server --mode development"
},
"dependencies": {
"core-js": "^3.8.3",
"vue": "^2.6.14",
"vue-loader": "^17.0.0",
"vue-router": "^3.5.3",
"webpack-dev-server": "^4.7.4"
},
"devDependencies": {
"@babel/core": "^7.17.7",
"@babel/eslint-parser": "^7.12.16",
"@babel/preset-env": "^7.16.11",
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"babel-loader": "^8.2.3",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3",
"vue-template-compiler": "^2.6.14",
"webpack": "^5.70.0",
"webpack-cli": "^4.9.2"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "@babel/eslint-parser"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}

最佳答案

Vue 2 在 vue-loader@16+ 使用时无法工作

npm i -D vue-loader@15.9.8

关于vue.js - 使用 Vue 2 设置 Webpack 5 时出现 "Cannot find module ' vue/compiler-sfc'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71516672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com