Gatsby 3.0:如何消除这个yarn / webpack解析器警告?

9

发生了什么

我刚刚升级了gatsby 2到3。

在其背后,它现在使用webpack 5代替4,并且现在发出一个依赖警告,我无法摆脱- raw-loader 安装为主项目和 gatsby 的依赖项,尽管它是相同的版本。

我尝试在我的package.json中指定yarn解析,如下所示:

  "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

这个问题

我应该如何正确配置gatsby或我的package.json文件,以便正确解决这个问题?

1个回答

3
我找到的一种解决方法是这样做:
rm -rf node_modules/gatsby/node_modules/raw-loader

这明显会迫使Node在树的顶部只找到单个依赖项。这样可以消除恼人的警告消息,但我真的想正确解决这个问题。

编辑

gatsby的github上一个相关的问题让我能够解决这个问题,因为它与webpack依赖关系相关。虽然,解决方案需要解决gatsby和webpack的兼容性,所以你必须提供一个解决方案。


你最终找到了更好的解决方案,还是这就是最好的呢?:) 谢谢! - zoul
@zoul 我已经编辑了答案,并附上了一个链接,这个问题让我绕过了这个特定的分辨率,虽然它并没有真正变得更好。此外,您可以查看我的网站存储库,它不再受到这个问题的困扰。 - thclark
完美,谢谢! - zoul
修复相关问题,消除这些警告信息!! - Cross

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接