发生了什么
我刚刚升级了盖茨比2 ->3 .
在底层,它现在使用webpack5而不是4,并且现在给出了一个我无法摆脱的依赖警告-raw-loader
被安装为主项目和gatsby的依赖项,即使它们是相同的版本。
我试着在我的package.json
中指定一个纱线分辨率,它看起来像这样:
"resolutions": {
"raw-loader": "4.0.2"
},
但这似乎没有任何作用。我也试过:
"resolutions": {
"gatsby/raw-loader": "4.0.2"
},
完整输出
⠙ Caching HTML renderer compilation
<w> [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Resolving 'raw-loader/dist/cjs' in /Users/myname/source/octue/planex-site/node_modules/gatsby/node_modules/loader-runner/lib for build dependencies doesn't lead to expected result '/Users/myname/source/octue/planex-site/node_modules/raw-loader/dist/cjs.js', but to '/Users/myname/source/octue/planex-site/node_modules/gatsby/node_modules/raw-loader/dist/cjs.js' instead. Resolving dependencies are ignored for this path.
<w> at unknown 4 raw-loader/dist/cjs
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/node_modules/loader-runner/lib/loadLoader.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/node_modules/loader-runner/lib/loadLoader.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/node_modules/loader-runner/lib/LoaderRunner.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/node_modules/loader-runner/lib/LoaderRunner.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/node_modules/webpack/lib/NormalModule.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/node_modules/webpack/lib/NormalModule.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/node_modules/webpack/lib/index.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/node_modules/webpack/lib/index.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/internal-plugins/functions/gatsby-node.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/internal-plugins/functions/gatsby-node.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/bootstrap/resolve-module-exports.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/bootstrap/resolve-module-exports.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/bootstrap/load-plugins/validate.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/bootstrap/load-plugins/validate.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/bootstrap/load-plugins/index.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/bootstrap/load-plugins/index.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/bootstrap/load-config-and-plugins.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/bootstrap/load-config-and-plugins.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/utils/worker/child/load-config-and-plugins.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/utils/worker/child/load-config-and-plugins.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/utils/worker/child/index.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/utils/worker/child/index.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby-worker/dist/index.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby-worker/dist/index.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/utils/worker/messaging.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/utils/worker/messaging.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/utils/jobs/worker-messaging.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/utils/jobs/worker-messaging.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/redux/actions/public.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/redux/actions/public.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/redux/actions/index.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/redux/actions/index.js
<w> at file dependencies /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/utils/webpack.config.js
<w> at file /Users/myname/source/octue/planex-site/node_modules/gatsby/dist/utils/webpack.config.js
yarn why
输出
$ yarn why raw-loader
yarn why v1.22.10
[1/4] 🤔 Why do we have the module "raw-loader"...?
[2/4] 🚚 Initialising dependency graph...
[3/4] 🔍 Finding dependency...
[4/4] 🚡 Calculating file sizes...
=> Found "raw-loader@4.0.2"
info Reasons this module exists
- "gatsby" depends on it
- Hoisted from "gatsby#raw-loader"
- Hoisted from "@storybook#addon-docs#@storybook#builder-webpack4#raw-loader"
info Disk size without dependencies: "32KB"
info Disk size with unique dependencies: "240KB"
info Disk size with transitive dependencies: "2.92MB"
info Number of shared dependencies: 14
我如何正确配置盖茨比或我的包。Json之类的来正确解决这个问题?
我发现的一个解决方法是:
rm -rf node_modules/gatsby/node_modules/raw-loader
…这显然迫使node只能在树的顶端找到一个依赖项。这样可以避免恼人的警告信息,但我真的想正确地解决这个问题。
编辑
一个与盖茨比的github密切相关的问题使我能够删除这个,因为它与webpack依赖相关。不过,该解决方案需要兼容盖茨比和webpack的分辨率,因此无论哪种方式,您都必须实际提供分辨率。