TypeError: Cannot destructure property 'Server' of '_engineIo.default'
richardeschloss opened this issue · 5 comments
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
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
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'
I have the same problem with nuxt stable version. Is there any way currently to work around this problem?
I did a research, so far I've seen none.