-
Notifications
You must be signed in to change notification settings - Fork 47
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
fix(types): fixed an issue with TypeScript not being able to locate .d.ts
with moduleResolution: node16
#150
fix(types): fixed an issue with TypeScript not being able to locate .d.ts
with moduleResolution: node16
#150
Conversation
Oh I can see the issue, but the problem with the solution (adding the conditional export I think the reason is that now, with the conditional export I think this is how we should reconfigure "exports": {
".": {
"import": "./dist/esm/tiny-invariant.js",
"default": {
"types": "./dist/esm/tiny-invariant.d.ts",
"default": "./dist/tiny-invariant.cjs.js"
}
}
} (we don't need to specify Such nested conditions ( What do you think @Andarist? |
I created the issue #151 for this so that folks running into the issue can find it. |
@pkerschbaum could you push out a repo that would manifest the issue that you are talking about? I agree with everything that you have mentioned - I would just like to understand the issue itself better. |
I will leave it to you two to let me know what to do on this one. I am out of my area of familiarity |
I think I've found another issue with this - but one that was also present in 1.3.0. Because you are using function invariant(condition, message) { /* ... */ }
module.exports = invariant; But all export default function invariant(condition: any, message?: string | (() => string)): asserts condition; The problem is that if we transpile the consuming project down to CJS and if that uses "use strict";
exports.__esModule = true;
var tiny_invariant_1 = require("tiny-invariant");
console.log(tiny_invariant_1["default"]); This is a potential runtime crash because at runtime there is no I mean, this can be solved by using |
Oh damn. So probably best to deprecate |
@alexreardon I've just added an edit to my latest comment:
So this was always the case, it's not unique for 1.3.0. It's just that perhaps with the |
I am not totally following. My most pressing questions:
|
If I can release a fix in |
….d.ts` with `moduleResolution: node16`
7fe0bb0
to
66eade7
Compare
|
@Andarist here is a repo: https://github.com/pkerschbaum/node-3rxg4d |
Okay, i'll hold off deprecating |
Co-authored-by: Patrick Kerschbaum <patrick.kerschbaum@gmail.com>
I think the suggestion "put exports.types first" of the TypeScript team means to put it first if you need to tweak it, and it is first in the nested export condition in |
Ok, I've pushed out the change - it's ready to land. cc @alexreardon @pkerschbaum did you have a chance to take a look at this? What's your take? should the |
LGTM now Actually, the |
You are both heros |
|
I have a project setup with the following {
"compilerOptions": {
"target": "es2020",
"module": "es2022",
"moduleResolution": "NodeNext"
}
} |
Should we fix that in another PR? Given there is no regression on that one, we could look at a future change to improve it |
v1.3.1 is working from my point of view.
|
@Andarist Referring to your comment above - I reproduced the issue here: https://stackblitz.com/edit/node-v9cajx ❯ npm run build-and-run
$ tsc && node ./dist/test.js
TypeError: (0 , tiny_invariant_1.default) is not a function
at Object.eval (/home/projects/node-v9cajx/dist/test.js:4:30)
at Object.function (https://node-v9cajx.w.staticblitz.com/blitz.b2ae50562a0bdf31ecd871b5c7a8c6dd539613de.js:15:141393)
at Module._compile (https://node-v9cajx.w.staticblitz.com/blitz.b2ae50562a0bdf31ecd871b5c7a8c6dd539613de.js:6:219079)
at Module._extensions..js (https://node-v9cajx.w.staticblitz.com/blitz.b2ae50562a0bdf31ecd871b5c7a8c6dd539613de.js:6:219743)
at Module.load (https://node-v9cajx.w.staticblitz.com/blitz.b2ae50562a0bdf31ecd871b5c7a8c6dd539613de.js:6:217769)
at Module._load (https://node-v9cajx.w.staticblitz.com/blitz.b2ae50562a0bdf31ecd871b5c7a8c6dd539613de.js:6:215340)
at Function.executeUserEntryPoint [as runMain] (https://node-v9cajx.w.staticblitz.com/blitz.b2ae50562a0bdf31ecd871b5c7a8c6dd539613de.js:6:989710)
at 𝐰𝐜_0x4dc6 (https://node-v9cajx.w.staticblitz.com/blitz.b2ae50562a0bdf31ecd871b5c7a8c6dd539613de.js:6:1603835)
at _0x34b558 (https://node-v9cajx.w.staticblitz.com/blitz.b2ae50562a0bdf31ecd871b5c7a8c6dd539613de.js:8:36028)
at _0x5d6daf (https://node-v9cajx.w.staticblitz.com/blitz.b2ae50562a0bdf31ecd871b5c7a8c6dd539613de.js:15:105049) As you said, in a
...the runtime error occurs. But since no one reported an issue for that, I think there is no need for us to change anything. |
I've confirmed locally that it fixes the issue with such
tsconfig.json
:See the comment by the TS member and the author of those new module resolutions here: microsoft/TypeScript#50890 (comment)