Error: Cyclic dependency after updating nuxt to v2.3.4

Error: Cyclic dependency after updating nuxt to v2.3.4

块资产优化后卡住 (93%)

显示这样的错误 /node_modules/toposort/index.js:35 抛出新错误('Cyclic dependency' + nodeRep)

我不断收到此错误。为了更新我的应用程序,我仔细按照步骤操作,但仍然没有任何结果。 请查收。

      throw new Error('Cyclic dependency' + nodeRep)
      ^

Error: Cyclic dependency
    at visit (/var/www/html/app/node_modules/toposort/index.js:35:13)
    at visit (/var/www/html/app/node_modules/toposort/index.js:53:9)
    at visit (/var/www/html/app/node_modules/toposort/index.js:53:9)
    at visit (/var/www/htmlapp/node_modules/toposort/index.js:53:9)
    at Function.toposort [as array] (/var/www/html/app/node_modules/toposort/index.js:22:22)
    at Object.module.exports.dependency (/var/www/html/app/node_modules/html-webpack-plugin/lib/chunksorter.js:50:35)
    at HtmlWebpackPlugin.sortChunks (/var/www/html/app/node_modules/html-webpack-plugin/index.js:364:35)

...

当我尝试在一个组件中延迟加载多个子组件时,我遇到了同样的错误。

问题原因

问题是由名为 toposort which is used by html-webpack-plugin on versions < 4.0.0 (it was removed) 的库引起的。

Nuxt 在 v2.13.

中将 html-webpack-plugin 更新为 v4

解决方案

解决方案 1

将 Nuxt 更新到版本 v2.13 或更高版本。

解决方案 2

如果您无法将 Nuxt 更新到 v2.13 或更新的版本,您可以在 nuxt.config.js

中应用以下解决方案

nuxt.config.js

const htmlPlugin = config.plugins.find(_ => _.constructor.name === 'HtmlWebpackPlugin')
if (htmlPlugin) {
  Object.assign(htmlPlugin.options, { chunksSortMode: 'none' })
}

我从 nuxtvue-cli 存储库中报告的以下问题中得到了解决方案:

也是vue-cli中应用的解决方案: