【vue项目升级node版本】Module not found: Error: Can‘t resolve “async hooks’问题解决方案

308 阅读1分钟

最近在尝试将公司项目迁移到新版的node环境中,即从node14升级到node16。遇到了不少的问题,最后快见到胜利的曙光时,存在两个老顽固警告,虽然不影响项目运行,但是会报错遮挡浏览器窗口,下面给出报错截图: 在这里插入图片描述 在网上查找很久,没有发现可行的解决方案,最后是大佬指导我去stackOverFlow网站查找解决方案,最终得以解决。 解决方案网址:点击这里跳转

警告原因是两个依赖引用了async_hooks依赖,但是未能成功访问到,这里的解决办法是将async_hooks进行屏蔽。 不卖关子了,直接上我解决的方法:

在项目的vue.config.js文件中,对象configureWebpack下的,plugins中加入下面代码:

new IgnorePlugin({
    resourceRegExp: /async_hooks/,
  }),

即:

configureWebpack: {
        //...
        plugins: [
            new WebpackBar({
                name: title
            }),
            new IgnorePlugin({
                resourceRegExp: /async_hooks/,
              })
        ],
        //...
    }

问题成功解决!

image.png