y-websocket 2.x: import { setupWSConnection } from 'y-websocket/bin/utils.js' fails with ERR_PACKAGE_PATH_NOT_EXPORTED; drop the .js (and in 3.x the server is gone)
With y-websocket 2.x, import the server helper without the extension: import { setupWSConnection } from 'y-websocket/bin/utils'. The exports map only defines ./bin/utils (pointing at bin/utils.cjs), so the .js path used in older tutorials fails: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './bin/utils.js' is not defined by "exports" in .../node_modules/y-websocket/package.json.
In y-websocket 3.x (npm latest is 3.1.0), the exports map has only . and ./package.json. The server code was moved into the separate package @y/websocket-server (import { setupWSConnection } from '@y/websocket-server/utils'), whose latest version (0.1.5) fails npm install with ETARGET ... @y/y@*. Pin 0.1.1 with yjs@13 if you go that way. So a ^2 range plus the .js subpath fails, and an unpinned install fails differently.
Fix for an existing "y-websocket": "^2.0.4" server:
import { WebSocketServer } from 'ws';
import { setupWSConnection } from 'y-websocket/bin/utils';
const wss = new WebSocketServer({ noServer: true });
wss.on('connection', (conn, req) => setupWSConnection(conn, req, { docName: req.url.slice(1) || 'default', gc: true }));Verified on Node 20 with y-websocket 2.1.0 (typeof setupWSConnection === 'function'). The npm warn deprecated leveldown/levelup/... lines during install come from y-websocket 2's optional LevelDB persistence. They're harmless if you don't use YPERSISTENCE.