Closed benbai123 closed 6 months ago
Does it works with 0.50.0? May be a regression introduced by #918 .
cc @hjdhjd
nope, tried 0.49.0 and 0.50.0, same error
Could you submit a PR to fix the issue?
I don't think there is a PR needed here - the issue is with the compilation options the user is using, not the code itself.
Try using:
tsconfig.json:
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": [
"DOM",
"ES2022"
],
"module": "ES2022",
"moduleResolution":"node",
"outDir": "dist",
"rootDir": "src",
"sourceMap": true,
"strict": true,
"target": "ES2022"
},
"include": [
"src"
]
}
Ensure package.json has "type": "module"
in there as well.
@robertsLando I can confirm that everything is working as it should be with the existing release.
confirmed, need "type": "module"
and 2 key compiler options.
{
// ...
"module": "ES2022",
"moduleResolution":"node",
}
btw, the compiler options I used before are copied from NestJS
tried run Aedes with NestJS, failed as expected.
workaround for NestJS :
import * as Aedes from 'aedes'
import { createServer } from 'net'
const port = 1883
const aedes = Aedes.createBroker()
const server = createServer(aedes.handle)
server.listen(port, function () {
console.log('server started and listening on port ', port)
})
found another ts compiler option "esModuleInterop": true
working with NestJS, but probably will break some other packages like jwks-rsa
raw-body
Ensure package.json has "type": "module" in there as well.
@hjdhjd So it only works with ESM now? Does it always require type module??
System Information
Describe the bug Run official example, Aedes is undefined and got error
TypeError: aedes_1.default is not a constructor
To Reproduce Steps to reproduce the behavior:
create 3 files below and run shell
npm install && npm run start
package.json
tsconfig.json
/src/main.ts
Expected behavior Should start a broker
Additional context
main.js