The Wayback Machine - https://web.archive.org/web/20201104093234/https://github.com/uNetworking/uWebSockets.js/issues/379
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

Invalid type declaration when used from ES module #379

Closed
qwelias opened this issue Oct 29, 2020 · 1 comment
Closed

Invalid type declaration when used from ES module #379

qwelias opened this issue Oct 29, 2020 · 1 comment
Labels
FAQ

Comments

@qwelias
Copy link

@qwelias qwelias commented Oct 29, 2020

There are three possible cases:

import * as uWS from 'uWebSockets.js';
console.log(uWS.App); // uWS.App has correct function signature, but is actually `undefined`
import uWS from 'uWebSockets.js/uws.js';
console.log(uWS.App); // uWS.App has type `any`, but is actually a function
import uWS from 'uWebSockets.js';
// Module '"${project_path}/node_modules/uWebSockets.js/index"' has no default export.ts(1192)
console.log(uWS.App); // uWS.App has type `any`, but is actually a function

How to reproduce

NodeJS 14
tsconfig.json:

{
    "compilerOptions": {
        "moduleResolution": "Node",
        "module": "ES2020",
        "target": "ES2020",
        "allowJs": true,
        "checkJs": true,
        "strict": false,
        "noEmit": true
    },
    "include": [
        "**/*.js",
        "**/*.ts"
    ],
    "exclude": [
        "node_modules"
    ]
}

package.json:

{
    "name": "project",
    "version": "0.1.0",
    "type": "module",
    "dependencies": {
        "uWebSockets.js": "github:uNetworking/uWebSockets.js#v18.9.0"
    },
    "devDependencies": {
        "@types/node": "^14.14.5",
        "typescript": "^4.0.5"
    }
}

Put any of the above three code snippets into test.js.
Run node test.js

P.S.

I did try different combinations of moduleResolution, module, and target, but alas.

@qwelias
Copy link
Author

@qwelias qwelias commented Oct 29, 2020

Fixed by enabling "esModuleInterop": true
🤦

@qwelias qwelias closed this Oct 29, 2020
@alexhultman alexhultman added the FAQ label Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.
Morty Proxy This is a proxified and sanitized view of the page, visit original site.