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

Usage in NextJS Apps #210

Open
mikelfcosta opened this issue Sep 16, 2022 · 5 comments
Open

Usage in NextJS Apps #210

mikelfcosta opened this issue Sep 16, 2022 · 5 comments

Comments

@mikelfcosta
Copy link

Hey!

I've used this library really well in SPA apps and express servers, and it worked perfectly with the schema validation and environment configs.

While trying to use it in a NextJS app, I ran into the following issues:

  • I could not use the NodeJS apis. Although I can import, run and read the configs successfully, it does not run on the Edge runtime that has no access to NodeJS native APIs (throws errors since some of those libs are not found).
  • I could not use the Webpack Plugin since it fails as there is no HtmlWebpack Plugin

Has anyone had success using this lib with a NextJS app, or if there are any plans for a plugin to support it?

@joelgallant
Copy link
Contributor

Hey thanks! I don't know very much about the NextJS build pipeline. But it sure sounds like a plugin we could build, similar (if not using) to the webpack plugin. You're right that today, the webpack plugin does only work if using the HTML plugin, something that most people do today.

You might be able to use the webpack plugin with headerInjection: false though. I think that's the only option that requires the HTML plugin.

@fstylermiller
Copy link
Contributor

Looking at it, headerInjection: false doesn't quite solve the issue. While it may be the only config option using the plugin, the index file still tries to import from the library. Given that it's a peer dependency of @app-config/webpack it might not be best to assume the package exists in the index file.

Checking to see if the module exists first using require.resolve("html-webpack-plugin") might be a solution.

@joelgallant
Copy link
Contributor

the index file still tries to import from the library

Oh! The import there makes sense, I didn't notice that. So a lazy load instead would likely work.

@fstylermiller
Copy link
Contributor

I'm looking to create a PR to lazy load the module! It doesn't seem that I have access to push to a new branch.

@fstylermiller
Copy link
Contributor

I was able to create a PR for lazy loading:
#218

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

No branches or pull requests

3 participants