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

ATA: Unable to resolve sub module path for dual published ESM/CJS package #3008

Open
sinclairzx81 opened this issue Dec 30, 2023 · 5 comments

Comments

@sinclairzx81
Copy link

sinclairzx81 commented Dec 30, 2023

Page URL:

TypeScript Link Here

Example Code:

Code above

import { Type } from '@sinclair/typebox'        // ok
import { Value } from '@sinclair/typebox/value' // not found

Issue:

I'm not sure if this is a critical issue, but following a recent update to support dual published ESM / CJS in TypeBox. I have noticed that the TSP is no longer able to locate the /value sub module (or any other sub module), however the top level module import continues to work fine. I have checked to ensure TS resolution of sub module paths are valid for the package via the link below, I believe everything is setup correctly.

https://arethetypeswrong.github.io/?p=%40sinclair%2Ftypebox%400.32.4

I should note that this package uses a somewhat non-typical package redirection setup to support dual publishing. The technique it uses is described at the following link / project.

https://github.com/andrewbranch/example-subpath-exports-ts-compat/tree/main/examples/node_modules/package-json-redirects

Would be amazing if this could be looked at as I use the TSP almost daily to help users who have submitting issues to the TypeBox project. It would be a shame to lose the sub module imports as many type inference features exists for these sub modules, and it would be difficult to demonstrate functionality and share code via other means.

Many Thanks

@sinclairzx81 sinclairzx81 changed the title CRITICAL: Unable to resolve sub module path for dual published ESM/CJS package TSP: Unable to resolve sub module path for dual published ESM/CJS package Dec 30, 2023
@jakebailey
Copy link
Member

This is the repo for TypeScript's website... Did you mean to file this on the typebox repo?

@sinclairzx81
Copy link
Author

sinclairzx81 commented Dec 31, 2023

Hi @jakebailey !

This is the repo for TypeScript's website... Did you mean to file this on the typebox repo?

Yes, I did mean to submit here :) (assuming this is the correct place to submit issues for the TypeScript Playground). If there is a better place to submit issues for the TypeScript Playground, please let me know! :)


As for the issue itself, it seems specific to submodule resolution on the TypeScript Playground; where it's lost the ability to import submodules from the TypeBox package. Note the issue only relates to the TypeScript Playground, as importing these submodules works fine in a local environment (vscode, language service and compiler)

Also note, this issue has only appeared since TypeBox introduced ESM + CJS dual publishing, where it currently uses a package redirection technique (linked above) to achieve this. This technique seems to be both "valid" and yet very "non-typical", with the technique seemingly tripping up resolution on the TSP.

It may be helpful to take a look at how the package setup on NPM (notice that submodule directories only contain a package.json file which redirects imports elsewhere)

https://www.npmjs.com/package/@sinclair/typebox?activeTab=code


I am open to this being an issue with TypeBox (and would certainly fix if that is the case), but as far as I can tell everything seems to be configured correctly (as indicated by this tool)

image

Submitting here just in case there is something a miss with TSP resolution.

@jakebailey
Copy link
Member

Oops. I didn't see who filed the issue.

It's possible that the playground's implementation of ATA can't handle it. Likely we should yank the new "APA" out of vscode.dev (which runs an actual package manager via wasm in the browser).

@jakebailey
Copy link
Member

To be honest, I don't quite get the layout; the one tshy uses is a lot simpler and likely would work out of the box.

@sinclairzx81
Copy link
Author

sinclairzx81 commented Dec 31, 2023

@jakebailey Thanks for the follow up on this!

the one tshy uses is a lot simpler and likely would work out of the box.

Yeah, I've just become aware of tshy, will be taking a deeper look into it in the new year.

To be honest, I don't quite get the layout

Yeah, the setup is a quite different. It was selected to support dual publishing and extensionless submodule pathing contrasted with the following criteria.

  • Modules must be resolvable without a tsconfig.json file present.
  • Modules must be resolvable with moduleResolution configured to node configured (a common misconfiguration)
  • Sub modules resolvable in all cases (this one has been challenging)

The package-json-redirect technique seems to achieve the above and makes TS and Node happy locally, it also enables downstream bundlers (esbuild / webpack) to do their thing...however the configuration hasn't been entirely without issue .... it's just that it seems to yield less issues than other layouts I've tried! :)

It's possible that the playground's implementation of ATA can't handle it. Likely we should yank the new "APA" out of vscode.dev (which runs an actual package manager via wasm in the browser).

This would be amazing!

@sinclairzx81 sinclairzx81 changed the title TSP: Unable to resolve sub module path for dual published ESM/CJS package ATA: Unable to resolve sub module path for dual published ESM/CJS package Jan 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants