抑制过长的webpack/Babel警告

gblwokeq  于 2022-12-13  发布在  Webpack
关注(0)|答案(1)|浏览(182)

在一个项目上运行npm run start:webpack的脚本会产生一个长达数页的亮黄色警告:
[webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo]解析node_modules/@babel/插件提议对象剩余扩展/node_modules/@ babel/助手编译目标/库中生成依赖项'@babel/助手编译目标/库/过滤器项'未产生预期结果'node_modules/@babel/插件提议对象剩余扩展/node_modules/@ babel/助手编译目标/库/过滤器项. js',而改为“node_modules/@babel/插件建议-对象-剩余-扩展/node_modules/@babel/助手-编译-目标/node_modules/@babel/助手-编译-目标/lib/过滤器项.js”。此路径的解析依赖项被忽略。在未知4@babel/助手-编译-目标/lib/过滤器项
(The堆栈跟踪继续。)
这使得很难发现其他警告或错误。
我试过将@babel/core升级到7.19并更新它的插件,将git提交一分为二以找到它的起始位置,搜索web--所有这些都没有成功。
如何诊断、修复或隐藏此警告?

kqlmhetl

kqlmhetl1#

我有相同的警告,但路径略有不同...添加了换行符和缩进以提高可读性:

Resolving '@babel/helper-compilation-targets/lib/filter-items' 
  in <PROJECT_PATH>/node_modules/workbox-build/node_modules/@babel/helper-define-polyfill-provider/node_modules/@babel/helper-compilation-targets/lib
    for build dependencies doesn't lead to expected result 
      '<PROJECT_PATH>/node_modules/workbox-build/node_modules/@babel/helper-define-polyfill-provider/node_modules/@babel/helper-compilation-targets/lib/filter-items.js'
        but to 
      '<PROJECT_PATH>/node_modules/workbox-build/node_modules/@babel/helper-define-polyfill-provider/node_modules/@babel/helper-compilation-targets/node_modules/@babel/helper-compilation-targets/lib/filter-items.js' 
    instead. Resolving dependencies are ignored for this path.

它的要点似乎是Webpack试图解决这个问题:

@babel/helper-compilation-targets/lib/filter-items

并且,它期望它解析为:

<PROJECT_PATH>/node_modules/workbox-build/node_modules/@babel/helper-define-polyfill-provider/node_modules/@babel/helper-compilation-targets/lib/filter-items.js

但是,它会解析为:

<PROJECT_PATH>/node_modules/workbox-build/node_modules/@babel/helper-define-polyfill-provider/node_modules/@babel/helper-compilation-targets/node_modules/@babel/helper-compilation-targets/lib/filter-items.js

奇怪的是,它看起来像@babel/helper-compilation-targets有自己的内部node_modules目录!🤔🤷🏻‍♂️
我设法通过删除那个(无关的?)包来“修复”这个问题:

rm -rf <PROJECT_PATH>/node_modules/workbox-build/node_modules/@babel/helper-define-polyfill-provider/node_modules/@babel/helper-compilation-targets/node_modules/@babel/helper-compilation-targets/

您还可以添加一个postinstall脚本,以便在每次安装后自动执行此操作:

scripts: {
  "postinstall": "rimraf node_modules/workbox-build/node_modules/@babel/helper-define-polyfill-provider/node_modules/@babel/helper-compilation-targets/node_modules/@babel/helper-compilation-targets"
}

相关问题