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

TypeError: Cannot destructure property 'Server' of '_engineIo.default' #657

Closed
richardeschloss opened this issue Oct 19, 2022 · 5 comments
Closed
Labels
bug Something isn't working
Milestone

Comments

@richardeschloss
Copy link

richardeschloss commented Oct 19, 2022

Describe the bug
A clear and concise description of what the bug is.

In a library I've written, when I attempt to import from "socket.io", I encounter an error "TypeError: Cannot destructure property 'Server' of '_engineIo.default'. I am able to fix this by updating the first line in wrapper.mjs:

import * as lib from "./build/engine.io.js"; // instead of: import lib from "./build/engine.io.js", which assumes a default export

Please let me know if you'd be open to the proposed change. I can submit the PR if you'd like.

Linked issue: https://github.com/richardeschloss/nuxt-socket-io/issues/278

@richardeschloss richardeschloss added the bug Something isn't working label Oct 19, 2022
@darrachequesne
Copy link
Member

Hi! Unfortunately I'm not able to reproduce the issue, either with TS/plain JS or CJS/ESM imports.

Could it be linked to nuxt/nuxt#14790?

Note: the current wrapper matches the documentation there: https://nodejs.org/docs/latest-v16.x/api/packages.html#approach-1-use-an-es-module-wrapper

@richardeschloss
Copy link
Author

richardeschloss commented Oct 19, 2022

Ok. Let's keep this issue open for the time being. It's possibly a Nuxt issue (which now uses jiti, which contains a bit more context unjs/jiti#87).

Reproduction

Install nuxt3 latest (rc12) with npm install nuxt@npm:nuxt3@latest (NOTE: Nuxt3 is still not stable).

The way to reproduce is, inside a minimal Nuxt project, create a module, say "lib/module.js", use the following config:

export default defineNuxtConfig({
  modules: [ './lib/module.js']
  build: {
    // transpile: ['engine.io'] // doesn't help
  }
})

Inside "./lib/module.js":

import { Server } from 'socket.io'
console.log(Server) // should print to the console

npm run dev # runs "nuxi dev"

Result

TypeError: Cannot destructure property 'Server' of '_engineIo.default'

@u-hafner
Copy link

I have the same problem with nuxt stable version. Is there any way currently to work around this problem?

@TheOfficialDaveyDave
Copy link

I did a research, so far I've seen none.

darrachequesne added a commit that referenced this issue Jan 10, 2023
The package does not have a default export, so importing it from a
project using ES modules would break in some cases.

> Cannot destructure property 'Server' of '_engineIo.default'

Related: #657
@darrachequesne
Copy link
Member

This should be fixed by ed87609, included in version 6.3.0. We'll release a new version of socket.io soon.

Please reopen if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants