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

Using with @next/bundle-analyzer removes all process.env variable when use with config function #14969

Closed
illuminist opened this issue Jul 8, 2020 · 5 comments

Comments

@illuminist
Copy link
Contributor

Bug report

Describe the bug

I added @next/bundle-analyzer to analyze bundle size in next.config.js, then all environment variable in env config got ignored.

To Reproduce

  1. Install @next/bundle-analyzer
  2. Add @next/bundle-analyzer to next.config.js, according to https://www.npmjs.com/package/@next/bundle-analyzer#usage-with-environment-variables.
  3. The config is a function that return the config object.
  4. Include env property in returned config object. Let's call it TESTME
  5. Get or print out process.env.TESTME, it will be undefined.

https://codesandbox.io/s/pedantic-gagarin-xiqgl?file=/next.config.js

Expected behavior

process.env.TESTME should have its value.

Removing withBundleAnalyzer() will make process.env.TESTME hold its own value correctly.

Also, this effects only function that returns config object. Passing config object directly into withBundleAnalyzer() seems to work normally.

System information

  • OS: Linux, tested in CodeSandbox
  • Version of Next.js: 9.4.4
  • Version of @next/bundle-analyzer: 9.4.4
@timneutkens
Copy link
Member

Something like this would work:

const withBundleAnalyzer = require('@next/bundle-analyzer')({
  enabled: process.env.ANALYZE === 'true',
})

module.exports = (phase) => {
  return withBundleAnalyzer({})
}

@illuminist
Copy link
Contributor Author

Maybe the document of @next/bundle-analyzer should be clearer on how to use with config function. Should I open for PR?

@timneutkens
Copy link
Member

Sure that's fine!

illuminist added a commit to illuminist/next.js that referenced this issue Jul 8, 2020
@illuminist
Copy link
Contributor Author

PR #14976

kodiakhq bot pushed a commit that referenced this issue Jul 9, 2020
#14969

It didn't specify on how to include the config with function config. This PR clarify the way to use the config with function.
rokinsky pushed a commit to rokinsky/next.js that referenced this issue Jul 11, 2020
vercel#14969

It didn't specify on how to include the config with function config. This PR clarify the way to use the config with function.
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants