套接字IO客户端错误:SyntaxError:请求的模块'@socket.io/component-emitter'预计将是类型的commonjs
我正在使用nextjs,我安装了软件包socket.io-client,并且在尝试导入时,根据文档:
import { io } from "socket.io-client";
我正在收到此错误:
SyntaxError: The requested module '@socket.io/component-emitter' is expected to be of type CommonJS, which does not support named exports. CommonJS modules
can be imported by importing the default export.
For example:
import pkg from '@socket.io/component-emitter';
const { Emitter } = pkg;
导入在index.js中
I'm using nextjs, I install the package socket.io-client, and when trying to import, according to the docs:
import { io } from "socket.io-client";
I'm receiving this error:
SyntaxError: The requested module '@socket.io/component-emitter' is expected to be of type CommonJS, which does not support named exports. CommonJS modules
can be imported by importing the default export.
For example:
import pkg from '@socket.io/component-emitter';
const { Emitter } = pkg;
The import is in index.js
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现原因是我正在使用的过时节点版本!
I found out that the reason is an outdated Node version I was using!