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

Replace cosmiconfig with lilconfig to Work with Webpack #34

Merged
merged 1 commit into from
Jun 18, 2024
Merged

Replace cosmiconfig with lilconfig to Work with Webpack #34

merged 1 commit into from
Jun 18, 2024

Conversation

CHC383
Copy link

@CHC383 CHC383 commented Jun 17, 2024

Partially fix #29

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. next-logger uses the sync API of cosmiconfig to load its config, which internally uses import-fresh to handle the config loading, and import-fresh underneath uses the plain require. This has been causing the issues mentioned in #13 (comment) and #29

While trying to fix the issue (PR: sindresorhus/import-fresh#27), it seems that import-fresh is not actively maintained. lilconfig is a zero-dependency alternative to cosmiconfig with the same API and more lightweight, and just released a new version 3.1.2 with the same fix.

I am proposing to use lilconfig instead in this PR to fix the config loading issue and hopefully avoid some issues caused by legacy components in the future.

Testing

  • npm run test
  • npm run lint

Webpack will replace `require` and `import` by default, `lilconfig` is a zero-dependency laternative to `cosmiconfig` with the same API, and the most recent version handles the webpack case.
@CHC383
Copy link
Author

CHC383 commented Jun 17, 2024

Renamed the branch and rebased on top of latest main, so replacing #31 with this one

@atkinchris
Copy link
Collaborator

Great write up! Thank you for contributing this fix @CHC383.

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.

it fails to import the winston logger.
3 participants