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

Change moduleResolution to nodenext #1000

Merged
merged 3 commits into from
Jul 26, 2024
Merged

Conversation

raphaelmenges
Copy link
Contributor

@raphaelmenges raphaelmenges commented May 26, 2024

According to the TypeScript documentation, the moduleResolution should be set to either NodeNext, Node16, or Bundler to fully support ESM-style imports in NodeJS. I have changed the the .tsconfigs accordingly. However, this changes seems to require to add .js to all imports of local files. I find this ugly and would be happy if somebody knows a way to not add the .js extensions for every local import.

I am also not sure about the casing for the module resolution strategy - followed the suggestions by my IDE. Feel free to change them to lower case.

This pull requests may resolve #997.

@raphaelmenges raphaelmenges marked this pull request as draft May 26, 2024 11:45
@raphaelmenges
Copy link
Contributor Author

The quite popular module mathjs also requires all relative imports to feature the .js extension after moving to ESM: https://github.com/josdejong/mathjs?tab=readme-ov-file#code

Thus, I guess this is the way. I would be fine with merging the pull-request as-is to the template.

@raphaelmenges raphaelmenges marked this pull request as ready for review June 13, 2024 10:25
@raphaelmenges
Copy link
Contributor Author

Since there were no further suggestions, I have changed the PR from draft to an open pull request!

@kryshac
Copy link

kryshac commented Jul 5, 2024

it is possible without .js

{
  ...
  "compilerOptions": {
    "moduleResolution": "bundler",
    "target": "ES2022",
    "module": "ES2022",
    ...
  }
}

@raphaelmenges
Copy link
Contributor Author

raphaelmenges commented Jul 6, 2024

Nice! But is it also "correct" or "modern" without .js? I am not sure what is the intended way 🤔

PS: I can verify that when I use Bundler for moduleResolution, we do not need to use the .js extension for imports! If this is the desired way, I can change the pull request correspondingly.

@cawa-93 cawa-93 merged commit 54e64a9 into cawa-93:main Jul 26, 2024
9 checks passed
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.

Change moduleResolution to node16 or nodenext
3 participants