-
-
Notifications
You must be signed in to change notification settings - Fork 865
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
Compiled build inlines PORT environment variable #356
Comments
I've also noticed that the way
This makes it impossible to make the server app configuration dynamic without rebuilding it every time. |
Hi @d4rky-pl, |
@xouabita this is nice, thanks :) I feel that Razzle should support this by default or have a caveat about |
This turns out to be even more problematic than I imagined. Let me explain: I'm writing a system tests runner (system tests: tests that run in actual browser) and I want to add razzle support from day one. The problem is that because PORT is inlined in resulting build, I have to also inline it when compiling everything before testing. This may cause unnecessary confusion when someone then tries to use the same build for something else (it's the production build after all, other than PORT there are zero changes) as the inlined PORT in tests is different than the one during "normal" production compilation. I could also drop the build after running tests but it will break the flow where we do system tests before production deployment and then reuse the same compiled code. @jaredpalmer please reconsider the decision to inline PORT in production build and add one-time lookup (something like |
@d4rky-pl let's make this right. what if we blacklisted
I;m sure you probably know this, but reading from |
I like this. In case of As for |
I had the same problem, also happens with env vars not defined at buildtime. This is the workaround: /* eslint-disable no-param-reassign */
const razzleConfigEnv = require('razzle/config/env');
module.exports = {
modify: (config, { target, dev }, webpack) => {
// Fix process.env
if (target === 'node') {
config.plugins = config.plugins.filter(plugin => plugin.constructor.name !== 'DefinePlugin');
const dotenv = razzleConfigEnv.getClientEnv(target, {
clearConsole: true,
host: 'localhost',
port: 3000
});
config.plugins.push(
new webpack.DefinePlugin({
'process.env': `Object.assign(${JSON.stringify(dotenv.raw)}, process.env)`
})
);
}
return config;
}
}; |
This is my workaround for Heroku: // getPorts.js
// bypass webpack.DefinePlugin
const { env } = require('process')
export const port = () =>
parseInt(
env.RAZZLE_PORT ||
env.PORT ||
process.env.RAZZLE_PORT ||
process.env.PORT ||
3000,
10,
) |
Heroku prohibits you from setting a port on startup. They are going to generate a port for you and then you are going to listen for it as an env var. - https://help.heroku.com/P1AVPANS/why-is-my-node-js-app-crashing-with-an-r10-error Unfortunately, Razzle defaults to setting port 3000 if you don't set one yourself. - https://github.com/jaredpalmer/razzle#build-time-variables There's some issues about this on the razzle repo, and ultimately this is where I found the solution. Source: jaredpalmer/razzle#356 (comment)
Heroku prohibits you from setting a port on startup. They are going to generate a port for you and then you are going to listen for it as an env var. - https://help.heroku.com/P1AVPANS/why-is-my-node-js-app-crashing-with-an-r10-error Unfortunately, Razzle defaults to setting port 3000 if you don't set one yourself. - https://github.com/jaredpalmer/razzle#build-time-variables There's some issues about this on the razzle repo, and ultimately this is where I found the solution. Source: jaredpalmer/razzle#356 (comment)
Heroku prohibits you from setting a port on startup. They are going to generate a port for you and then you are going to listen for it as an env var. - https://help.heroku.com/P1AVPANS/why-is-my-node-js-app-crashing-with-an-r10-error Unfortunately, Razzle defaults to setting port 3000 if you don't set one yourself. - https://github.com/jaredpalmer/razzle#build-time-variables There's some issues about this on the razzle repo, and ultimately this is where I found the solution. Source: jaredpalmer/razzle#356 (comment)
Hola! So here's the deal, between open source and my day job and life and what not, I have a lot to manage, so I use a GitHub bot to automate a few things here and there. This particular GitHub bot is going to mark this as stale because it has not had recent activity for a while. It will be closed if no further activity occurs in a few days. Do not take this personally--seriously--this is a completely automated action. If this is a mistake, just make a comment, DM me, send a carrier pidgeon, or a smoke signal. |
ProBot automatically closed this due to inactivity. Holler if this is a mistake, and we'll re-open it. |
Heroku prohibits you from setting a port on startup. They are going to generate a port for you and then you are going to listen for it as an env var. - https://help.heroku.com/P1AVPANS/why-is-my-node-js-app-crashing-with-an-r10-error Unfortunately, Razzle defaults to setting port 3000 if you don't set one yourself. - https://github.com/jaredpalmer/razzle#build-time-variables There's some issues about this on the razzle repo, and ultimately this is where I found the solution. Source: jaredpalmer/razzle#356 (comment)
I found a pretty simple workaround to this issue, if people are still struggling with it
|
I tried this but when I try 'npm run start:prod' on my local, I get an error that assets.json not found. Also, could you please advise, do I need to upload node_modules in build folder as well as I get npm package related errors as well. |
This is working for me now. `
` |
This was preventing me from deploying to Dokku. Related issue: jaredpalmer/razzle#356
Due to how
getClientEnvironment
is written, PORT environment variable is being inlined into final build instead of being kept asprocess.env.PORT
.This will cause Razzle to fail launching on Heroku using start:prod
The text was updated successfully, but these errors were encountered: