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

Module resolution problems #342

Closed
2 tasks
thorn0 opened this issue Oct 11, 2023 · 6 comments
Closed
2 tasks

Module resolution problems #342

thorn0 opened this issue Oct 11, 2023 · 6 comments
Labels
bug Something isn't working pr welcome released

Comments

@thorn0
Copy link

thorn0 commented Oct 11, 2023

Problem

This package doesn't play well with TypeScript when moduleResolution is set to NodeNext.

See https://arethetypeswrong.github.io/?p=esbuild-loader%404.0.2 for a detailed explanation of the problem.

Possible solutions:

  1. remove "type": "module" from package.json
  2. or rename dist/index.d.ts -> dist/index.d.cts

Expected behavior

I expected this line

import { EsbuildPlugin } from "esbuild-loader";

to keep working after I changed the moduleResolution option in tsconfig.json from Node to NodeNext.

For now we use a dynamic import as a workaround.

Minimal reproduction URL

https://stackblitz.com/edit/node-1zhtpc?file=foo.ts&view=editor

Version

4.0.2

Node.js version

16+

Package manager

npm

Operating system

Windows

Contributions

  • I plan to open a pull request for this issue
  • I plan to make a financial contribution to this project
@thorn0 thorn0 added bug Something isn't working pending triage labels Oct 11, 2023
@privatenumber
Copy link
Owner

I see why it's technically not correct, but I'd like to make sure I'm seeing the same problem first.

In your reproduction, I'm still able to get the correct types when I add:

import { EsbuildPlugin } from "esbuild-loader";
Screenshot 2023-10-11 at 1 20 41 PM

@thorn0
Copy link
Author

thorn0 commented Oct 11, 2023

Try this in a .ts CommonJS module, not in .js. That's why there is the foo.ts file in my reproduce.

@privatenumber
Copy link
Owner

privatenumber commented Oct 11, 2023

Whys it imported from a .ts file? It's designed to be imported from a Webpack config file

FYI Setting "allowJs": true works too

@thorn0
Copy link
Author

thorn0 commented Oct 11, 2023

webpack is a library. CLI is not the only way to use it.

@privatenumber
Copy link
Owner

Could've just said "I'm using Webpack via Node rather than the CLI" instead of the snarky response.

Feel free to submit a PR.

@privatenumber
Copy link
Owner

🎉 This issue has been resolved in version 4.0.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pr welcome released
Projects
None yet
Development

No branches or pull requests

2 participants