ricokahler / next-plugin-preval

Pre-evaluate async functions during builds and import them like JSON
MIT License
255 stars 12 forks source link

Environment variables are all undefined when next-plugin-preval is wrapped with `@sentry/nextjs` webpack plugin #42

Closed Vadorequest closed 3 years ago

Vadorequest commented 3 years ago

PR: https://github.com/UnlyEd/next-right-now/pull/370/files

http://localhost:8888/api/status

image

This is the expected behavior and that's what happens when not using @sentry/nextjs OR when using withNextPluginPreval as top-level wrapper.

module.exports = withNextPluginPreval(withSentryConfig(...

http://localhost:8888/api/status

image

This is what happens when using module.exports = withSentryConfig(withNextPluginPreval(...


I'm not sure what's going wrong, but it drove me crazy for an hour. Since @sentry/nextjs explicitly stated to wrap all webpack config, I assumed it would be safe and didn't notice the regression right away.

ricokahler commented 3 years ago

This may be an upstream issue with withSentryConfig.

There are few different interfaces for this next config (e.g. in particular, it could take in a function, or take in an object). If the upstream plugin isn't handling all of those cases, it could result in something not propagating correctly. I'll take a look!

ricokahler commented 3 years ago

Looking at their latest source code, I can confirm that @sentry/nextjs is not handling the case when next.js config is a function.

https://github.com/getsentry/sentry-javascript/blob/62619534e524693f160663bb076a38edba475a19/packages/nextjs/src/utils/config.ts#L126-L129

compare that to next-plugin-preval:

https://github.com/ricokahler/next-plugin-preval/blob/f89525dfe8a1e01d5d450a9d610acbeeacf4e05b/src/create-next-plugin-preval.ts#L25-L28

this explains why it works when withNextPluginPreval is last and not vice versa. next-plugin-preval always returns a function since it accepts one.

Vadorequest commented 3 years ago

Thank you for taking such a quick look and idenfitying the issue! I'll forward this to them and close it here then!

ricokahler commented 3 years ago

I think there's something I can do about this though. I've heard similar issues from people using next-compose-plugins with this lib so maybe I'm making some wrong assumptions. I'll open a separate issue for that.

lobsterkatie commented 3 years ago

Thanks for spotting that, @ricokahler. It's a known problem and is on our list to fix this sprint.