skip to content
天真笔录

yarn问题记录

/ 3 min read

yarn升级问题记录

yarn1升级yarn3后项目完全跑不起来

启动报错


Generated code for /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/css-loader-virtual-74cafbe12e/0/cache/css-loader-npm-6.7.3-63aa933400-473cc32b6c.zip/node_modules/css-loader/dist/cjs.js!/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/vue-loader-virtual-303d2eabbf/0/cache/vue-loader-npm-17.0.1-f552b82805-42cc8c8ff0.zip/node_modules/vue-loader/dist/stylePostLoader.js!/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/postcss-loader-virtual-bc861325fe/0/cache/postcss-loader-npm-7.1.0-28d8160cdf-44e4018a8f.zip/node_modules/postcss-loader/dist/cjs.js??clonedRuleSet-3.use[2]!/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/sass-loader-virtual-57291e1ae0/0/cache/sass-loader-npm-13.2.0-6421c5ff7b-ed6cdb5f55.zip/node_modules/sass-loader/dist/cjs.js!/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/vue-loader-virtual-303d2eabbf/0/cache/vue-loader-npm-17.0.1-f552b82805-42cc8c8ff0.zip/node_modules/vue-loader/dist/index.js??ruleSet[1].rules[11].use[0]!/Users/a1/workspace/dmeo-project/webpack-srqc1/src/views/layout/component/shuangfeiyi.vue?vue&type=style&index=0&id=d38a7eba&lang=scss&scoped=true
1 | throw new Error("Module build failed (from ./.yarn/__virtual__/postcss-loader-virtual-bc861325fe/0/cache/postcss-loader-npm-7.1.0-28d8160cdf-44e4018a8f.zip/node_modules/postcss-loader/dist/cjs.js):\nError: postcss-loader tried to access postcss (a peer dependency) but it isn't provided by your application; this makes the require call ambiguous and unsound.\n\nRequired package: postcss (via \"postcss/package.json\")\nRequired by: postcss-loader@virtual:8b28b0b7cff82f0341c2690e9542c0419eb98efa7b64ee01dbabdbb652429362ef1175a0674e240cd3c1a2f106c75d5db6b193a1e0fe6489c34080230b082608#npm:7.1.0 (via /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/postcss-loader-virtual-bc861325fe/0/cache/postcss-loader-npm-7.1.0-28d8160cdf-44e4018a8f.zip/node_modules/postcss-loader/dist/)\nAncestor breaking the chain: webpack-srqc1@workspace:.\n\n\nRequire stack:\n- /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/postcss-loader-virtual-bc861325fe/0/cache/postcss-loader-npm-7.1.0-28d8160cdf-44e4018a8f.zip/node_modules/postcss-loader/dist/index.js\n- /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/postcss-loader-virtual-bc861325fe/0/cache/postcss-loader-npm-7.1.0-28d8160cdf-44e4018a8f.zip/node_modules/postcss-loader/dist/cjs.js\n- /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/loadLoader.js\n- /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/LoaderRunner.js\n- /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-virtual-37bd4f4aa2/0/cache/webpack-npm-5.76.2-e7c563c5c0-86db98299a.zip/node_modules/webpack/lib/NormalModule.js\n- /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/vue-loader-virtual-303d2eabbf/0/cache/vue-loader-npm-17.0.1-f552b82805-42cc8c8ff0.zip/node_modules/vue-loader/dist/pluginWebpack5.js\n- /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/vue-loader-virtual-303d2eabbf/0/cache/vue-loader-npm-17.0.1-f552b82805-42cc8c8ff0.zip/node_modules/vue-loader/dist/plugin.js\n- /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/vue-loader-virtual-303d2eabbf/0/cache/vue-loader-npm-17.0.1-f552b82805-42cc8c8ff0.zip/node_modules/vue-loader/dist/index.js\n- /Users/a1/workspace/dmeo-project/webpack-srqc1/webpack.config.js\n- /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-cli-virtual-4f723bb470/0/cache/webpack-cli-npm-4.10.0-09cee8c457-2ff5355ac3.zip/node_modules/webpack-cli/lib/webpack-cli.js\n- /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-cli-virtual-4f723bb470/0/cache/webpack-cli-npm-4.10.0-09cee8c457-2ff5355ac3.zip/node_modules/webpack-cli/lib/bootstrap.js\n- /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-cli-virtual-4f723bb470/0/cache/webpack-cli-npm-4.10.0-09cee8c457-2ff5355ac3.zip/node_modules/webpack-cli/bin/cli.js\n- /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-dev-server-virtual-2e0ebc200e/0/cache/webpack-dev-server-npm-4.13.0-3fa2f79921-7546dd3b5a.zip/node_modules/webpack-dev-server/bin/webpack-dev-server.js\n    at Function.require$$0.Module._resolveFilename (/Users/a1/workspace/dmeo-project/webpack-srqc1/.pnp.cjs:18271:13)\n    at Function.require$$0.Module._load (/Users/a1/workspace/dmeo-project/webpack-srqc1/.pnp.cjs:18121:42)\n    at Module.require (node:internal/modules/cjs/loader:1057:19)\n    at require (node:internal/modules/cjs/helpers:103:18)\n    at Object.<anonymous> (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/postcss-loader-virtual-bc861325fe/0/cache/postcss-loader-npm-7.1.0-28d8160cdf-44e4018a8f.zip/node_modules/postcss-loader/dist/index.js:9:39)\n    at Module._compile (node:internal/modules/cjs/loader:1155:14)\n    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)\n    at Object.require$$0.Module._extensions..js (/Users/a1/workspace/dmeo-project/webpack-srqc1/.pnp.cjs:18315:33)\n    at Module.load (node:internal/modules/cjs/loader:1033:32)\n    at Function.require$$0.Module._load (/Users/a1/workspace/dmeo-project/webpack-srqc1/.pnp.cjs:18152:14)\n    at Module.require (node:internal/modules/cjs/loader:1057:19)\n    at require (node:internal/modules/cjs/helpers:103:18)\n    at Object.<anonymous> (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/postcss-loader-virtual-bc861325fe/0/cache/postcss-loader-npm-7.1.0-28d8160cdf-44e4018a8f.zip/node_modules/postcss-loader/dist/cjs.js:3:18)\n    at Module._compile (node:internal/modules/cjs/loader:1155:14)\n    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)\n    at Object.require$$0.Module._extensions..js (/Users/a1/workspace/dmeo-project/webpack-srqc1/.pnp.cjs:18315:33)\n    at Module.load (node:internal/modules/cjs/loader:1033:32)\n    at Function.require$$0.Module._load (/Users/a1/workspace/dmeo-project/webpack-srqc1/.pnp.cjs:18152:14)\n    at Module.require (node:internal/modules/cjs/loader:1057:19)\n    at require (node:internal/modules/cjs/helpers:103:18)\n    at loadLoader (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/loadLoader.js:19:17)\n    at iteratePitchingLoaders (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/LoaderRunner.js:182:2)\n    at iteratePitchingLoaders (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/LoaderRunner.js:178:10)\n    at /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/LoaderRunner.js:189:18\n    at handleResult (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/loadLoader.js:53:2)\n    at loadLoader (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/loadLoader.js:35:10)\n    at iteratePitchingLoaders (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/LoaderRunner.js:182:2)\n    at iteratePitchingLoaders (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/LoaderRunner.js:178:10)\n    at /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/LoaderRunner.js:189:18\n    at handleResult (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/loadLoader.js:53:2)\n    at loadLoader (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/loadLoader.js:35:10)\n    at iteratePitchingLoaders (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/LoaderRunner.js:182:2)\n    at runLoaders (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/loader-runner-npm-4.3.0-9ca67df372-a90e00dee9.zip/node_modules/loader-runner/lib/LoaderRunner.js:398:2)\n    at NormalModule._doBuild (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-virtual-37bd4f4aa2/0/cache/webpack-npm-5.76.2-e7c563c5c0-86db98299a.zip/node_modules/webpack/lib/NormalModule.js:821:3)\n    at NormalModule.build (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-virtual-37bd4f4aa2/0/cache/webpack-npm-5.76.2-e7c563c5c0-86db98299a.zip/node_modules/webpack/lib/NormalModule.js:965:15)\n    at /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-virtual-37bd4f4aa2/0/cache/webpack-npm-5.76.2-e7c563c5c0-86db98299a.zip/node_modules/webpack/lib/Compilation.js:1371:12\n    at NormalModule.needBuild (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-virtual-37bd4f4aa2/0/cache/webpack-npm-5.76.2-e7c563c5c0-86db98299a.zip/node_modules/webpack/lib/NormalModule.js:1253:32)\n    at Compilation._buildModule (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-virtual-37bd4f4aa2/0/cache/webpack-npm-5.76.2-e7c563c5c0-86db98299a.zip/node_modules/webpack/lib/Compilation.js:1352:10)\n    at /Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-virtual-37bd4f4aa2/0/cache/webpack-npm-5.76.2-e7c563c5c0-86db98299a.zip/node_modules/webpack/lib/util/AsyncQueue.js:303:10\n    at Hook.eval [as callAsync] (eval at create (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/cache/tapable-npm-2.2.1-8cf5ff3039-3b7a1b4d86.zip/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)\n    at AsyncQueue._startProcessing (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-virtual-37bd4f4aa2/0/cache/webpack-npm-5.76.2-e7c563c5c0-86db98299a.zip/node_modules/webpack/lib/util/AsyncQueue.js:293:26)\n    at AsyncQueue._ensureProcessing (/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-virtual-37bd4f4aa2/0/cache/webpack-npm-5.76.2-e7c563c5c0-86db98299a.zip/node_modules/webpack/lib/util/AsyncQueue.js:280:12)\n    at processImmediate (node:internal/timers:466:21)");
 @ ./src/views/layout/component/shuangfeiyi.vue?vue&type=style&index=0&id=d38a7eba&lang=scss&scoped=true 1:0-1125 1:0-1125
 @ ./src/views/layout/component/shuangfeiyi.vue 4:0-83
 @ ./.yarn/__virtual__/babel-loader-virtual-057b3e8f8d/0/cache/babel-loader-npm-8.3.0-a5239d7ed2-d48bcf9e03.zip/node_modules/babel-loader/lib/index.js??clonedRuleSet-1.use[0]!./.yarn/__virtual__/vue-loader-virtual-303d2eabbf/0/cache/vue-loader-npm-17.0.1-f552b82805-42cc8c8ff0.zip/node_modules/vue-loader/dist/index.js??ruleSet[1].rules[11].use[0]!./src/views/layout/Layout.vue?vue&type=script&setup=true&lang=js 2:0-52 16:17-26
 @ ./src/views/layout/Layout.vue?vue&type=script&setup=true&lang=js 1:0-435 1:0-435 1:436-860 1:436-860
 @ ./src/views/layout/Layout.vue 2:0-68 3:0-63 3:0-63 8:49-55
 @ ./src/views/layout/index.js 3:0-34 6:20-26

ERROR in ./src/views/index/App.vue?vue&type=template&id=e109b6cc&scoped=true&ts=true (./.yarn/__virtual__/ts-loader-virtual-c3e1e33cff/0/cache/ts-loader-npm-9.4.2-ad41a3f9dc-6f306ee4c6.zip/node_modules/ts-loader/index.js??clonedRuleSet-2!./.yarn/__virtual__/vue-loader-virtual-303d2eabbf/0/cache/vue-loader-npm-17.0.1-f552b82805-42cc8c8ff0.zip/node_modules/vue-loader/dist/templateLoader.js??ruleSet[1].rules[3]!./.yarn/__virtual__/vue-loader-virtual-303d2eabbf/0/cache/vue-loader-npm-17.0.1-f552b82805-42cc8c8ff0.zip/node_modules/vue-loader/dist/index.js??ruleSet[1].rules[11].use[0]!./src/views/index/App.vue?vue&type=template&id=e109b6cc&scoped=true&ts=true) 1:0-188
Module not found: Error: Can't resolve 'vue' in '/Users/a1/workspace/dmeo-project/webpack-srqc1/src/views/index'
 @ ./src/views/index/App.vue?vue&type=template&id=e109b6cc&scoped=true&ts=true 1:0-597 1:0-597
 @ ./src/views/index/App.vue 1:0-84 8:68-74 18:83-20:3 19:29-35 18:2-20:4
 @ ./src/views/index/index.js 2:0-28 8:10-13

ERROR in ./.yarn/__virtual__/webpack-dev-server-virtual-2e0ebc200e/0/cache/webpack-dev-server-npm-4.13.0-3fa2f79921-7546dd3b5a.zip/node_modules/webpack-dev-server/client/index.js?protocol=ws%3A&hostname=0.0.0.0&port=9000&pathname=%2Fws&logging=info&overlay=true&reconnect=10&hot=true&live-reload=true 8:0-47
Module not found: Error: Can't resolve 'webpack/hot/log.js' in '/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-dev-server-virtual-2e0ebc200e/0/cache/webpack-dev-server-npm-4.13.0-3fa2f79921-7546dd3b5a.zip/node_modules/webpack-dev-server/client'

ERROR in ./.yarn/__virtual__/webpack-dev-server-virtual-2e0ebc200e/0/cache/webpack-dev-server-npm-4.13.0-3fa2f79921-7546dd3b5a.zip/node_modules/webpack-dev-server/client/overlay.js 9:0-43
Module not found: Error: Can't resolve 'ansi-html-community' in '/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-dev-server-virtual-2e0ebc200e/0/cache/webpack-dev-server-npm-4.13.0-3fa2f79921-7546dd3b5a.zip/node_modules/webpack-dev-server/client'
 @ ./.yarn/__virtual__/webpack-dev-server-virtual-2e0ebc200e/0/cache/webpack-dev-server-npm-4.13.0-3fa2f79921-7546dd3b5a.zip/node_modules/webpack-dev-server/client/index.js?protocol=ws%3A&hostname=0.0.0.0&port=9000&pathname=%2Fws&logging=info&overlay=true&reconnect=10&hot=true&live-reload=true 12:0-60 110:46-59 224:27-40 252:28-41

ERROR in ./.yarn/__virtual__/webpack-dev-server-virtual-2e0ebc200e/0/cache/webpack-dev-server-npm-4.13.0-3fa2f79921-7546dd3b5a.zip/node_modules/webpack-dev-server/client/overlay.js 10:0-39
Module not found: Error: Can't resolve 'html-entities' in '/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-dev-server-virtual-2e0ebc200e/0/cache/webpack-dev-server-npm-4.13.0-3fa2f79921-7546dd3b5a.zip/node_modules/webpack-dev-server/client'
 @ ./.yarn/__virtual__/webpack-dev-server-virtual-2e0ebc200e/0/cache/webpack-dev-server-npm-4.13.0-3fa2f79921-7546dd3b5a.zip/node_modules/webpack-dev-server/client/index.js?protocol=ws%3A&hostname=0.0.0.0&port=9000&pathname=%2Fws&logging=info&overlay=true&reconnect=10&hot=true&live-reload=true 12:0-60 110:46-59 224:27-40 252:28-41

ERROR in ./.yarn/__virtual__/webpack-dev-server-virtual-2e0ebc200e/0/cache/webpack-dev-server-npm-4.13.0-3fa2f79921-7546dd3b5a.zip/node_modules/webpack-dev-server/client/utils/reloadApp.js 1:0-48
Module not found: Error: Can't resolve 'webpack/hot/emitter.js' in '/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-dev-server-virtual-2e0ebc200e/0/cache/webpack-dev-server-npm-4.13.0-3fa2f79921-7546dd3b5a.zip/node_modules/webpack-dev-server/client/utils'
 @ ./.yarn/__virtual__/webpack-dev-server-virtual-2e0ebc200e/0/cache/webpack-dev-server-npm-4.13.0-3fa2f79921-7546dd3b5a.zip/node_modules/webpack-dev-server/client/index.js?protocol=ws%3A&hostname=0.0.0.0&port=9000&pathname=%2Fws&logging=info&overlay=true&reconnect=10&hot=true&live-reload=true 15:0-45 200:4-13 244:4-13

ERROR in ./.yarn/__virtual__/webpack-virtual-37bd4f4aa2/0/cache/webpack-npm-5.76.2-e7c563c5c0-86db98299a.zip/node_modules/webpack/hot/emitter.js 1:19-36
Module not found: Error: Can't resolve 'events' in '/Users/a1/workspace/dmeo-project/webpack-srqc1/.yarn/__virtual__/webpack-virtual-37bd4f4aa2/0/cache/webpack-npm-5.76.2-e7c563c5c0-86db98299a.zip/node_modules/webpack/hot'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
        - add a fallback 'resolve.fallback: { "events": require.resolve("events/") }'
        - install 'events'

尝试解决

修改 .yarnrc.yml

nodeLinker: "node-modules"
pnpMode: "loose"

这会使yarn3与之前的yarn1扁平化安装行为一致,修改后可以运行

相关依赖

"devDependencies": {
  "@babel/core": "^7.18.6",
  "@babel/preset-env": "^7.18.6",
  "@vue/compiler-sfc": "^3.2.37",
  "autoprefixer": "^10.4.7",
  "babel-loader": "^8.2.5",
  "clean-webpack-plugin": "^4.0.0",
  "css-loader": "^6.7.1",
  "eslint": "^8.19.0",
  "eslint-webpack-plugin": "^3.2.0",
  "html-webpack-externals-plugin": "^3.8.0",
  "html-webpack-plugin": "^5.5.0",
  "mini-css-extract-plugin": "^2.6.1",
  "postcss-loader": "^7.0.0",
  "sass": "^1.53.0",
  "sass-loader": "^13.0.2",
  "style-loader": "^3.3.1",
  "thread-loader": "^3.0.4",
  "ts-loader": "^9.3.1",
  "vue-loader": "^17.0.0",
  "webpack": "^5.73.0",
  "webpack-cli": "^4.10.0",
  "webpack-dev-server": "^4.9.3"
},
"dependencies": {
  "glob": "7.2.0",
  "normalize.css": "^8.0.1",
  "typescript": "^4.7.4",
  "vant": "^4.1.1",
  "vue": "^3.2.37"
},

yarn version

3.4.1