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
Libs imported into Next.js apps do not have access to process.env in the client bundle #9633
Labels
Comments
If anyone else encounters this issue, we worked around it by adding the following in our next.config.js file: webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
if (config.name === "client") {
const envKeys = Object.keys(process.env).reduce((prev, key) => {
if (key.startsWith("NEXT_PUBLIC_")) {
prev[key] = JSON.stringify(process.env[key]);
}
return prev;
}, {});
config.plugins.push(
new webpack.DefinePlugin({
process: {
env: {
...envKeys
}
}
})
);
}
return config;
}, |
ndcunningham
pushed a commit
to ndcunningham/nx
that referenced
this issue
May 31, 2022
…m libraries ISSUES CLOSED: nrwl#9633
ndcunningham
pushed a commit
to ndcunningham/nx
that referenced
this issue
May 31, 2022
…m libraries ISSUES CLOSED: nrwl#9633 update update
ndcunningham
pushed a commit
to ndcunningham/nx
that referenced
this issue
Jun 1, 2022
…m libraries ISSUES CLOSED: nrwl#9633 update
ndcunningham
pushed a commit
to ndcunningham/nx
that referenced
this issue
Jun 1, 2022
…m libraries ISSUES CLOSED: nrwl#9633 update
I don't see any fixes here, only a test added? |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Current Behavior
Libs imported into Next.js apps do not have access to process.env their client bundles.
Expected Behavior
Libs imported into a Next.js app should be able to use environment variables and not cause an app to throw:
Steps to Reproduce
NEXT_PUBLIC_FOO=bar
.You will observe that "bar" renders correctly to the screen.
process
is not defined.Environment
The text was updated successfully, but these errors were encountered: