Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing "./build/esm-debug" specifier in "socket.io-client" package #4635

Closed
wvhulle opened this issue Feb 21, 2023 · 3 comments
Closed

Missing "./build/esm-debug" specifier in "socket.io-client" package #4635

wvhulle opened this issue Feb 21, 2023 · 3 comments
Labels
question Further information is requested
Milestone

Comments

@wvhulle
Copy link

wvhulle commented Feb 21, 2023

Describe the bug

The documentation is unable to help me to set up debugging in the client when installed through npm.
It only refers to cdn, but i cannot find anywhere on the Socket IO website or google how to import the esm-debug version.

Importing socket.io-client/build/esm-debug in Vite results in

Internal server error: Missing "./build/esm-debug" specifier in "socket.io-client" package

To Reproduce

localStorage.debug = "*"
No logs shown.

Server

socket.io 4.6.1

Client

socket.io-client 4.6.1

Expected behavior

Show debug statements in browser

Not possible

Platform:
Edge and Firefox
Vite

Additional context

@wvhulle wvhulle added the to triage Waiting to be triaged by a member of the team label Feb 21, 2023
@darrachequesne
Copy link
Member

Hi! We could indeed export the debug build, which is currently only available for the Node.js platform (here).

That being said, I am not sure whether Vite supports the exports field, something like:

{
  // ...
  "exports": {
    "/debug": {
      "import": "./build/esm-debug/index.js",
      "require": "./build/cjs/index.js",
      "types": "./build/esm/index.d.ts"
    }
  },
}

And then: import { io } from "socket.io-client/debug"

Reference: https://nodejs.org/api/packages.html#package-entry-points

What do you think?

@darrachequesne darrachequesne added question Further information is requested and removed to triage Waiting to be triaged by a member of the team labels Feb 23, 2023
@wvhulle
Copy link
Author

wvhulle commented Feb 23, 2023

I would have to check if vite supports that specifically for the client but I have found another way. In vite it is also possible to declare the path to the debug version as resolve alias. Then you can import it with a relative path in the client code, at least on the dev server. There is also some other issue with XMLrequest that can be resolved like this.

Besides that, in the server I also found out that it is possible to toggle debugging on and off by importing debug from debug and calling debug.enable. I prefer this to yet another environment variable.

Maybe this could be documented?

darrachequesne pushed a commit to socketio/socket.io-client that referenced this issue Jun 20, 2023
So that debug logs can be printed with vite:

```js
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [react()],
  server: {
    port: 4000
  },
  resolve: {
    conditions: ["development"]
  }
})
```

Reference: https://v2.vitejs.dev/config/#resolve-conditions

Related:

- socketio/socket.io#4731
- socketio/socket.io#4635
- https://github.com/socketio/socket.io-client/issues/1516
@darrachequesne darrachequesne added this to the 4.7.0 milestone Jun 20, 2023
@darrachequesne
Copy link
Member

This should be fixed by socketio/socket.io-client@781d753, included in version 4.7.0.

Please reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants