【问题标题】:Gatsby 3.0: How can I get rid of this yarn / webpack resolver warning?Gatsby 3.0:我怎样才能摆脱这个 yarn / webpack 解析器警告?
【发布时间】:2021-11-01 22:44:13
【问题描述】:

发生了什么

我刚刚升级了 gatsby 2 -> 3。

在底层它现在使用 webpack 5 而不是 4,现在给出了一个突出的依赖警告,我无法摆脱 - raw-loader 被安装为主项目和 gatsby 的依赖虽然是同一个版本

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

  "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 或其他任何东西以正确解决此问题?

【问题讨论】:

    标签: webpack gatsby yarnpkg raw-loader


    【解决方案1】:

    我发现的解决方法是:

    rm -rf node_modules/gatsby/node_modules/raw-loader
    

    ...这显然会迫使节点仅在树的顶部找到单个依赖项。这消除了烦人的警告消息,但我真的很想妥善解决这个问题。

    编辑

    A closely-related issue 在我工作的 gatsby 的 github 上使我能够删除它,因为它与 webpack 依赖项有关。虽然,该解决方案需要兼容 gatsby 和 webpack 的分辨率,因此无论哪种方式,您都必须实际提供分辨率。

    【讨论】:

    • 你最终找到了更好的解决方案,还是这样? :) 谢谢!
    • @zoul 我已经编辑了答案,并附上了指向该问题的链接,使我能够绕过这个特定的解决方案,尽管它并没有那么好。您也可以查看my site repo,它不再受此问题困扰
    • 完美,谢谢!
    猜你喜欢
    • 2011-03-12
    • 2021-01-27
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    • 2022-10-18
    • 2020-01-05
    • 1970-01-01
    相关资源
    最近更新 更多