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

Typescript ignores package.json export maps #58890

Open
paulmillr opened this issue Jun 16, 2024 · 5 comments
Open

Typescript ignores package.json export maps #58890

paulmillr opened this issue Jun 16, 2024 · 5 comments
Assignees
Labels
Needs More Info The issue still hasn't been fully clarified

Comments

@paulmillr
Copy link

paulmillr commented Jun 16, 2024

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.90.1
  • OS Version: macos 14.5

Steps to Reproduce:

  1. mkdir meth && cd meth && npm init -y && npm i micro-eth-signer && touch a.mjs
  2. Open a.mjs and enter import * as net from 'micro-eth-signer/net'; or any other module. VSCode would not see the module even though it's clearly specified in pkg.json
  3. Doesn't matter which tsconfig is used, i've tried all options (moduleResolution, module, whatever)

I maintain many libraries and I export their functionality in sub-modules instead of importing everything into one big index.js file. This is useful and helps with tree-shaking. Seems like vscode doesn't support export maps in node.js.

@VSCodeTriageBot
Copy link

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.90.1. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

@paulmillr
Copy link
Author

@VSCodeTriageBot upgraded to 1.90.1

@mjbvz mjbvz transferred this issue from microsoft/vscode Jun 17, 2024
@RyanCavanaugh
Copy link
Member

What are you expecting to see? This is what I get:
image

@RyanCavanaugh RyanCavanaugh added the Needs More Info The issue still hasn't been fully clarified label Jun 17, 2024
@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jun 19, 2024

Without any more info, I'll point out the following information about the package from https://arethetypeswrong.github.io/?p=micro-eth-signer%400.9.1

  "micro-eth-signer" "micro-eth-signer/abi" "micro-eth-signer/net" "micro-eth-signer/rlp" "micro-eth-signer/ssz" "micro-eth-signer/tx" "micro-eth-signer/utils"
node10
node16 (from CJS) ✅ (CJS) ✅ (CJS) ✅ (CJS) 💀 Resolution failed 💀 Resolution failed ✅ (CJS) ✅ (CJS)
node16 (from ESM) 🎭 Masquerading as CJS 🎭 Masquerading as CJS 🎭 Masquerading as CJS 💀 Resolution failed 💀 Resolution failed 🎭 Masquerading as CJS 🎭 Masquerading as CJS
bundler 💀 Resolution failed 💀 Resolution failed

Under node16, ESM files will think that you're trying to import a CJS file (because they resolve to a .d.ts file under a package.json that implies a CJS code). See here.

@paulmillr
Copy link
Author

paulmillr commented Jun 19, 2024

@DanielRosenwasser this looks very useful, thanks. I will fix "masquearading". RLP and SSZ modules are failing because of a typo from my end.

Here's another package of mine:

https://arethetypeswrong.github.io/?p=micro-key-producer%400.7.0

It says "💀 Resolution failed" for all node16. I assume this is simply because cjs files are located in lib subdir and node10 can't find it. So until node10 resolution is deprecated (unclear when that happens), we are forced to not use clean structure with "all files are in subdirs".

Now, the question related to the first post is: which module resolution does typescript currently enforce by default? Is it node10? I mean, for the situation when there is no "tsconfig", and a random JS file is checked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs More Info The issue still hasn't been fully clarified
Projects
None yet
Development

No branches or pull requests

5 participants