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

Q. How to work in webpack #331

Open
sacru2red opened this issue Sep 19, 2024 · 7 comments · Fixed by #333
Open

Q. How to work in webpack #331

sacru2red opened this issue Sep 19, 2024 · 7 comments · Fixed by #333

Comments

@sacru2red
Copy link

fails repo is here

and getting other message at other repo
image

@ryoppippi ryoppippi closed this as not planned Won't fix, can't repro, duplicate, stale Sep 19, 2024
@ryoppippi
Copy link
Owner

ryoppippi commented Sep 19, 2024

You change the repo so much (cjs -> esm)
Refer my example repo.
Just copy and paste the example

@ryoppippi
Copy link
Owner

@sacru2red I found that the example repo doesn't work in node v20.
Hmm, maybe we need to revert the docs?

@ryoppippi
Copy link
Owner

@sacru2red Ok I'll revert it

@ryoppippi
Copy link
Owner

Thank you for reporting as always

@sacru2red
Copy link
Author

ref. I am in [email protected], [email protected]

@sacru2red
Copy link
Author

@ryoppippi

I just realized that one incorrect commit was included when I provided the repo yesterday, and I have fixed it.
I also found and resolved a few more issues. (All build-tests have passed)

As a junior developer, I couldn't thoroughly investigate the root cause of the problem, but based on my understanding, the issue seems to be as follows:

  • Essentially, a webpack config file cannot be written as an ES module (webpack runtime is fixed to commonjs, I think?).
  • There is a way to write a webpack config file as a TS file. Link
  • Therefore, the value of tsconfig.compilerOptions.module must be set to commonjs.
  • In JavaScript, you can mix require and dynamic import.
  • In TypeScript, there are two options: the first is to transform the import into require, and the second is to keep it as import.
  • In this edge case, since compilerOptions.module is set to commonjs, we can't choose to keep the import statement.
  • However, there is still a way to keep the import statement. I used Option 4 from the linked discussion.

@ryoppippi ryoppippi reopened this Sep 20, 2024
@ryoppippi
Copy link
Owner

@sacru2red
Thank you for your investigation.
Hmm, there are lots of poitnts we consider....

So, Node v22 has require(esm) feature.
https://joyeecheung.github.io/blog/2024/03/18/require-esm-in-node-js/
If we can use it, we don't need jiti anymore.
Otherwise, we need keep using jiti

@ryoppippi ryoppippi closed this as not planned Won't fix, can't repro, duplicate, stale Sep 22, 2024
@ryoppippi ryoppippi reopened this Sep 22, 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

Successfully merging a pull request may close this issue.

2 participants