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

Stop relying on experimental-specifier-resolution #397

Merged
merged 1 commit into from
Sep 8, 2023

Conversation

divergentdave
Copy link
Contributor

This fixes #374 by adding .js extensions to all intra-package ESM import statements. I also removed the --experimental-specifier-resolution=node flag from mocha configuration and one other node command. I tested with the same external plain Node.js project I initially found this issue with, and it can import the packages from tarballs with no further intervention. Based on documentation, this appears to be the preferred way to handle ESM imports in TypeScript. (The project has rejected proposals to have tsc rewrite import statements, FWIW) I also confirmed that VS Code's go to definition feature correctly navigates to source .ts files when used on these updated import statements.

@divergentdave divergentdave requested review from jbr and a team as code owners September 8, 2023 20:45
@jbr
Copy link
Contributor

jbr commented Sep 8, 2023

I wonder if it would be preferable to have "type": "commonjs" now that we no longer require async import (which had been a requirement for wasm, I believe)

@jbr
Copy link
Contributor

jbr commented Sep 8, 2023

There seems to be in-flight updated documentation for ts modules here, in particular "I'm writing a library", but I haven't read it through yet

@divergentdave
Copy link
Contributor Author

I think sticking with "type": "module" makes sense. Our main use case is in the browser, and ESM is closer to the desired end result than CJS, even though there will often be a bundling step to produce a single file. Plus, since ESM is more expressive, it could help with tree shaking done by tools in the pipeline.

@jbr jbr merged commit 6a1dc22 into main Sep 8, 2023
4 checks passed
@jbr jbr deleted the david/fix-import-statements-node branch September 8, 2023 21:31
@jbr
Copy link
Contributor

jbr commented Sep 8, 2023

confirmed that const { DAPClient } = await import("@divviup/dap"); works with no flags provided to node's repl

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

Successfully merging this pull request may close these issues.

Packages cannot be imported from plain Node interpreter
2 participants