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
Support for NodeJS 12.7+ package exports #33079
Comments
Yeah, I know - I don't think we should implement support for it till it's stabilized - things like how |
I agree, this issue exists primarily to serve as a place for us to track the progress of this feature in NodeJS. |
Given node is now at v12.11.1 and I believe v12 will enter LTS soon has this functionality stabilised enough to warrant inclusion in typescript module resolution now? This will prove very helpful when working with yarn simlinked monorepos as the existing |
We spoke about it in the modules wg on Wednesday - it's going to unflag with es modules as a whole (even the cjs support), so it can be a reliable fallback-allowing mechanism for pre-esm node. It... Should... Unflag during the node 12 lifetime. But that hasn't happened yet, and details are still being fleshed out~ |
Looks like this has unflagged in 13.2.0: https://github.com/nodejs/node/blob/v13.2.0/doc/changelogs/CHANGELOG_V13.md#notable-changes (with support for |
Node 14 (next LTS) is scheduled for release 2020-04-21 and I'm guessing it will support exports unflagged as node 13 does and at that point I know I will want to use it :-). Is typescript planning to support exports in the same timeframe as the node 14 release? |
Yeah, we've just been waiting for it to stabilize a bit, since it's still experimental, even if it's unflagged (it emits a warning when it's used in resolution), since we don't want to need to support an old experimental version and a final version (and it does still see significant change - there's discussion about removing the |
Is there a way around this for the time being? Perhaps manually linking up modules via an I'm using path based modules such as It'd be ideal if there were a way to explicitly set these in the mean time. |
@okdecm, try setting the // packages/bar/tsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"rootDir": "src",
"outDir": "dist/lib",
"composite": true,
"paths": {
"@my/foo": [
"../foo/dist/lib/index"
],
"@my/foo/models": [
"../foo/dist/lib/a/b/c/d/models"
],
"@my/foo/*": [
"../foo/dist/lib/*"
]
}
},
"references": [{ "path": "../foo/tsconfig.json" }]
} The |
One of the ideas for conditional exports was to allow things like {
"name": "pkg",
/* [...] */
"exports": {
"./foo": {
"types": "./types/foo.d.ts",
"default": "./target.js"
},
"./bar/": {
"types": "./types/bar.d.ts",
"default": "./dist/nested/dir/"
}
}
} This would be great to see in a potential TypeScript integration. :) |
Any updates on this? |
I'm not sure I understand what the obstacle is? I would think that TS just needs to continue looking at the I have examples of this already. I'd expect these to Just Work This would be backwards compatible too, because a definition file that doesn't contain a |
An interesting tidbit is that if you load use a submodule inside a JS file, eg import * as colors from 'kleur/colors';
colors.r
// (js) has code completions
// (ts) *crickets* |
this |
Sort-of. Basic usecases are pretty stable, but a lot of conditional-related cases are still under discussion. Anyways, we've missed the mark for inclusion in 4.0, so 4.1 would be the earliest you'd see it. |
I've worked on it. You can tell Rollup exactly what entrypoints you are wanting to bundle and where you want to emit them. I'm asking you to give me a repro or something so I can show you, but you're just getting more frustrated. Ultimately none of this is your fault, none of this should be this complicated, as Andrew said it's an ecosystem thing, though TypeScript also drops the ball on a lot of it. But there is a way to configure your module the way you want it and if you give me a repro example I will help you do that, you just need to chill out a bit. Create a Replit repro with an example project that matches this structure, like you were opening a Rollup bug report, and if you send it I will help you get it configured properly. |
Node v11 is not of concern anymore, only Node 14+ are still supported. The exports field was backported to Node 12 when it was still a current version and thus should also be supported by typescript no matter the version. If Parcel and Browserify do not support it then that is on them to solve, either on their end or by providing typescript with a resolution model that would should be its own option in tsconfig - assuming it really is different from node.js' model. Having multiple different resolution models as a single option makes no sense at all. The The
I have linked to my repo multiple times in my comments. I have even provided a screenshot showing the shape of the build output after I fixed my own unrelated mistakes in file naming and changed declaration files to show up alongside files of the same name - contrary to what I initially had configured and knew was working. Everything is configured correctly, it always was and even after changes still is, I am actively using the packages in production with silly workarounds like the aforemention foxkit.d.ts file I have to manually copy between projects because TypeScript refuses to properly support a feature of node.js that was introduced many many years ago and my bug report for said feature is falling on deaf ears here. Again: I am not asking for help with an example, I am reporting a bug. Quit backseating my example. |
I’m offering to help you, you’re spamming everyone’s email because you are reasonably confused trying to get conditional exports resolution working. I see you made progress after moving the exports to index entrypoints per my recommendation though. And yes I believe you about whatever bug regarding weird types field needing to come first, good catch. You are also perfectly correct about it being time to drop support for <14. |
If me discussing this ticket, and my reason for wanting it reopened (was asked about prior to my first comment yesterday!) is just email spam to you I'm going to unsubscribe from this topic now. Usually it is liked when people give as much detail as possible in bug reports and respond to any queries. I will open another ticket when I've figured out a more concise way to word my bug report since excessive detail is not appreciated here. Pro tip: You can disable email alerts in the settings on your github profile and/or unsubscribe from topics. Github suggest doing such often enough in the notifications page. |
Renaming
I’m still having a hard time understanding exactly what the bug is. Your screenshots omit tsconfigs which are important, since package.json
Well, I guess I’m just replying into the aether |
For some reason the exports field is not working at least on Prisma PDP codebase.
Is there any update on this? |
@andrewbranch I'm curious; what problem do you have understanding what the bug is? @Mitsunee made it very clear that he expects TypeScript to follow package.json's If you follow any of the above referenced issues you'll find many examples, beyond what @Mitsunee already posted screenshots of. Here's another screenshot for your benefit: in this case, I expect not to have this error message in consuming code: In summary, TS should honour the package resolution mechanism. This is especially important if you ever expect modules to start moving from CommonJS to ECMAScript modules. It seems work has been done to support this; so for anyone finding this, even if you're on node14, you might be able to use |
Please cease mentioning me in this ticket. I've been told off from using this bug tracker because I'm "causing email spam", so please don't cause me email spam. There is clearly no interest in fixing type imports for libraries and I've found an (admittedly stupid and annoying) workaround that has been working for me. |
I hope it’s clear to everyone that the person who said this is a random community member completely unaffiliated with this project and doesn’t speak for Microsoft or TypeScript. Anyone with on-topic comments is always welcome to participate, and anyone who implies otherwise should be ignored. That said, this issue is closed and the conversation has not been very productive for some time. I have opened #50794 to track adding support for package.json I hate locking issues, so I’m not going to do that here just yet, but I can’t imagine how any further discussion here can be productive:
Please don’t make me lock this |
I have npm workspaces, each workspace exporting different modules with I was unable to import a module from a different workspace, until I changed module Resolution to node16. |
We do not set the `exports` in `package.json` as it seems to be not stable yet (see [this issue in TypeScript], for example). Therefore, we import the main module (`index.js`) and re-write the examples accordingly. [this issue in TypeScript]: microsoft/TypeScript#33079
We do not set the `exports` in `package.json` as it seems to be not stable yet (see [this issue in TypeScript], for example). Therefore, we import the main module (`index.js`) and re-write the examples accordingly. [this issue in TypeScript]: microsoft/TypeScript#33079
I'm confused over this conversation. I'm using vite & a pnpm monorepo with *.ts files that are automatically transpiled with vite/esbuild. Is something like this possible? I would rather keep my app files in *.ts instead of using *.js/*.d.ts {
"name": "my-package",
"exports": {
"./ui": "./src/ui/index.ts"
}
} or {
"name": "my-package",
"exports": {
"./ui": {
"types": "./src/ui/index.ts",
"default": "./src/ui/index.ts"
}
}
} |
NodeJS 12.7 added support for a (currently experimental) feature for custom package imports and exports in
package.json
: https://github.com/jkrems/proposal-pkg-exports/In short, this feature allows a package author to redirect exports in their package to alternate locations:
This is currently only available when
--experiemental-exports
is passed to NodeJS, however we should continue to track the development of this feature as it progresses.The text was updated successfully, but these errors were encountered: