套接字IO客户端错误:SyntaxError:请求的模块'@socket.io/component-emitter'预计将是类型的commonjs

发布于 2025-01-26 09:15:05 字数 475 浏览 1 评论 0原文

我正在使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫漫岁月 2025-02-02 09:15:05

我发现原因是我正在使用的过时节点版本!

I found out that the reason is an outdated Node version I was using!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文