-
Notifications
You must be signed in to change notification settings - Fork 340
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
Type definitions are broken in 4.0.0-beta.1 #169
Comments
Thanks for letting us know. Interestingly, types work fine for me with ESM, and CJS doesn't give any issue with both module resolution set to This is what I use to test: https://github.com/frederikprijck/jwt-decode-test You can run the following commands:
When running the cjs scripts, make sure to set All of these commands work fine for me, so I must be missing something to reproduce this. Could you perhaps let me know how you can reproduce it in that example? |
Ignore the above, I can perfectly reproduce the same issue by just running Adding the file extension to the import paths solves the issue, updating the exports field in package.json doesn't seem to have any additional affect based on what I can see, will need to look into this further. |
I opened a PR, that does seem to fix the issue with tsc, but will need a follow up for the commonjs types (but it should at least run). @remcohaszing any chance you can try that branch and see if it solves it on your end as well? If not, could you elaborate how to update my sample linked above to reproduce what you are seeing? |
I have some things in the works to fix up the types, both for CommonJS and ESM. We will have to follow the best practices as outlined by the TypeScript handbook (see my earlier comment #151 (comment)):
|
I fixed the test cases in frederikprijck/jwt-decode-test#1. Run I recommend to verify the package against Are The Types Wrong to make sure it’s built correctly. |
Got a PR up under #174 to fix this issue. |
I tested beta 1.0 with the current tsconfig which is the one we use at work {
"$schema": "https://json.schemastore.org/tsconfig",
"display": "TS Config",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"lib": [
"ESNext",
"DOM",
"DOM.Iterable"
],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noImplicitOverride": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"strict": true,
"target": "ESNext",
"useUnknownInCatchVariables": false,
"verbatimModuleSyntax": true
},
...
} Seems to work fine, but the same as pointed by others that the package is commonjs masquerading as ESM. |
If I understand correctly, the issues in this thread should be resolved with the current beta branch? Is that correct @remcohaszing? |
Yep, it’s working correctly now 🎉 |
Released as v4.0.0-beta.2! |
Checklist
Description
Type definitions are broken for both CJS and ESM.
Reproduction
Create the following files:
This yields the following type error:
This shows 2 errors:
jwt-decode
is ESM only, although there is a CJS entrypoint. To solve this, the exports inpackage.json
should look something like this:.js
in this case)Additional context
The current build setup is relatively complex. Dual publishing is pretty complex. I’m not sure how to fix it in this setup. An alternative solution is to use a named export instead of a default export.
jwt-decode version
4.0.0-beta.1
Which browsers have you tested in?
Other
The text was updated successfully, but these errors were encountered: