解决vue2 安装 unplugin-turbo-console 后启动报错 Error [ERR_REQUIRE_ESM]: require() of ES Module
vue2项目安装 unplugin-turbo-console@1.10.4
配置信息按官方书写如下
require('unplugin-turbo-console/webpack').default({
extendedPathFileNames: ['index']
}),
报错信息如下
ERROR Error [ERR_REQUIRE_ESM]: require() of ES Module F:\learn-front\vueuse-vue2-example\node_modules\crossws\dist\adapters\node.mjs not supported.
Instead change the require of F:\learn-front\vueuse-vue2-example\node_modules\crossws\dist\adapters\node.mjs to a dynamic import() which is available in all CommonJS modules.
Error [ERR_REQUIRE_ESM]: require() of ES Module F:\learn-front\vueuse-vue2-example\node_modules\crossws\dist\adapters\node.mjs not supported.
Instead change the require of F:\learn-front\vueuse-vue2-example\node_modules\crossws\dist\adapters\node.mjs to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (F:\learn-front\vueuse-vue2-example\node_modules\unplugin-turbo-console\dist\index.cjs:11:19)
at Object.<anonymous> (F:\learn-front\vueuse-vue2-example\node_modules\unplugin-turbo-console\dist\webpack.cjs:6:15)
控制台使用命令查看报错的依赖包
npm ls crossws
❯ npm ls crossws
vueuse-vue2-example@ F:\learn-front\vueuse-vue2-example
`-- unplugin-turbo-console@1.10.4
`-- h3@1.13.0
`-- crossws@0.3.1
定位h3,发现其github上源代码依赖的crossws@0.24,而当前版本依赖的crossws@0.3.1
使用yarn锁定版本,安装后启动正常
{
"resolutions": {
"crossws": "0.2.4"
}
}