@rollup/plugin-node-resolve throws error: Cannot read property 'length' of undefined

@rollup/plugin-node-resolve throws error: Cannot read property 'length' of undefined

我收到这个错误,它来自 @rollup/plugin-node-resolve

[!] TypeError: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
//...
at async Promise.all (index 0)
at async Promise.all (index 2)
at async Promise.all (index 0)
at async Promise.all (index 0)
at async Promise.all (index 0)

这是我的配置。我可以确认错误来自 @rollup/plugin-node-resolve

const config = {
  input: './build/sw.js',
  //Other configs
  }],
  plugins: [
    nodeResolve(),
    commonjs({
      include: ['./src/**', 'node_modules/**']
    })
  ]
}

我正在 sw.js

中导入以下工作箱依赖项

工作箱核心

workbox-预缓存

工作箱路由

工作箱策略

工作箱过期

workbox-背景同步

我该如何解决这个错误?

不是 100% 确定这个问题的原因,但我发现如果我没有在我的包中明确安装 Rollup,你将获得的 Rollup 版本 npx rollup -v1.x.x .将其升级到 2.x.x 将修复此错误。