8000 feat: Support Dynamic Import in Webpack Context by CHC383 · Pull Request #53 · antonk52/lilconfig · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Support Dynamic Import in Webpack Context #53

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

Merged
merged 2 commits into from
Jun 9, 2024
Merged

feat: Support Dynamic Import in Webpack Context #53

merged 2 commits into from
Jun 9, 2024

Conversation

CHC383
Copy link
@CHC383 CHC383 commented Jun 5, 2024

Credit: Thanks @jeremiegirault for proposing the changes in sindresorhus/import-fresh#21

Description

Webpack will try to bundle modules during compile time and replace the original require, so using require directly in the Webpack context to load configs could result in MODULE_NOT_FOUND error. Switching to __non_webpack_require__ to use plain require while in the Webpack environment.

About __non_webpack_require__:

Try to solve issues like:

Making these changes will eventually make it possible to replace cosmiconfig with lilconfig in next-logger

Test

npm run test

Webpack will try to bundle modules during compile time and replacing the original `require`, so using `require` directly in the Webpack context to load configs could result in `MODULE_NOT_FOUND` error. Switching to `__non_webpack_require__` to use plain `require` while in the Webpack environment.
@antonk52
Copy link
Owner
antonk52 commented Jun 6, 2024

Thanks for the PR and the detailed description. I am happy to merge the change to the requireFunc.

Can you please explain for the need to increase required nodejs version besides EOL? My initial impression is that it is unrelated to this PR and should be omitted. Making a change to required nodejs version is an unnecessary breaking change. Perhaps I am missing some context here. Can you expand on it?

Updating dependencies is out of scope for this PR. Please revert that commit.

@CHC383
Copy link
Author
CHC383 commented Jun 6, 2024

Remove both dependency and NodeJS changes, just want to make the code up-to-date but indeed they are unnecessary for this PR.

@antonk52
Copy link
Owner
antonk52 commented Jun 9, 2024

Thanks for updating the PR. I've tested the changes locally by bundling a cli app and it worked for the sync loader.

To merge this PR we need to also make it work for the async loader as currently webpack replaces native import(id) with __webpack_require__("./node_modules/lilconfig/src lazy recursive")(id).

To fix it please make the following change

-		const mod = await import(id);
+		const mod = await import(/* webpackIgnore: true */  id);

Once updated I am happy to merge this PR and release a new version.

@CHC383
Copy link
Author
CHC383 commented Jun 9, 2024

Thanks for the testing and suggestion, just updated the PR

@antonk52 antonk52 merged commit c81afbd into antonk52:master Jun 9, 2024
@antonk52
Copy link
Owner
antonk52 commented Jun 9, 2024

Published in v3.1.2

Thank you!

@shellscape
Copy link

@antonk52 any chance you know someone on the tailwindcss team? They're one of the bigger users and they're pinned to 2.1.0, and it's causing all kinds of havoc with next.js+tailwind projects and conflicting lilconfig versions in the bundle. tailwindlabs/tailwindcss#14029

@antonk52
Copy link
Owner
antonk52 commented Dec 3, 2024

Unfortunately, I don't know anyone directly. I can only suggest getting the PR rebased to be in a merge-able state and the latest lilconfig version. Then (maybe?) tag someone with merge permissions in said repository. While tagging people directly is a bad practice due to that issue will address a security vulnerability and support for large platforms such as windows sound important enough for me to ping someone directly.

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.

4 participants
0