我正在尝试在一个苗条的组件中设置 socket.io-client。
文档说我可以做到import { io } from 'socket.io-client'
。
但是当我尝试使用serve
目标运行应用程序时,命令失败并显示以下日志:
Bundle complete. Watching for file changes...
Bundling...
'bufferutil' is imported by bufferutil?commonjs-external, but could not be resolved – treating it as an external dependency
'utf-8-validate' is imported by utf-8-validate?commonjs-external, but could not be resolved – treating it as an external dependency
Circular dependency: node_modules\util\util.js -> node_modules\util\node_modules\inherits\inherits.js -> node_modules\util\util.js
Circular dependency: node_modules\util\util.js -> node_modules\util\node_modules\inherits\inherits.js -> C:\Users\munda\Documents\upwork\upwork-gameshow\node_modules\util\util.js?commonjs-proxy -> node_modules\util\util.js
@rollup/plugin-typescript: Rollup 'sourcemap' option must be set to generate source maps.
No name was provided for external module 'tty' in output.globals – guessing 'tty'
No name was provided for external module 'os' in output.globals – guessing 'os'
No name was provided for external module 'fs' in output.globals – guessing 'fs'
No name was provided for external module 'child_process' in output.globals – guessing 'require$$0'
No name was provided for external module 'http' in output.globals – guessing 'require$$1'
No name was provided for external module 'https' in output.globals – guessing 'require$$2'
No name was provided for external module 'net' in output.globals – guessing 'net'
No name was provided for external module 'tls' in output.globals – guessing 'tls'
No name was provided for external module 'crypto' in output.globals – guessing 'require$$0$3'
No name was provided for external module 'zlib' in output.globals – guessing 'zlib'
No name was provided for external module 'bufferutil' in output.globals – guessing 'require$$1$1'
No name was provided for external module 'stream' in output.globals – guessing 'require$$0$2'
No name was provided for external module 'utf-8-validate' in output.globals – guessing 'require$$0$1'
Creating a browser bundle that depends on Node.js built-in modules ("tty", "os", "http", "https", "zlib" and "stream"). You might need to include https://github.com/snowpackjs/rollup-plugin-polyfill-node
我生成应用程序的步骤:
- 使用启动 nx 工作区
yarn create nx-workspace
yarn add @nxext/svelte
使用链接安装 svelte 生成器: https ://nx.dev/community#:~:text=the%20Nx%20workflow-,%40nxext/svelte,-Nx%20plugin%20to- 使用已安装的生成器生成
svelte
应用程序。 - 在组件中添加
socket.io
客户端代码(文档中提到的基本套接字初始化)。 - 由于我的服务器和客户端不会托管在同一个域上,因此添加
import { io } from 'socket.io-client'
并初始化套接字使用const socket = io(SERVER_URL)
(在我的情况下是 http://localhost:3000) - 使用 . 安装 socket.io 客户端
yarn socket.io-client
。 - 使用,手指交叉运行
serve
目标。nx run-many --target=serve --all --parallel
结果:上述日志。
我错过了什么?