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

Always overriding NODE_ENV with development #691

Open
MilosMoravac opened this issue May 23, 2024 · 7 comments
Open

Always overriding NODE_ENV with development #691

MilosMoravac opened this issue May 23, 2024 · 7 comments

Comments

@MilosMoravac
Copy link

MilosMoravac commented May 23, 2024

Expected Behavior

When NODE_ENV is specified it should override development and not the other way around.

Current Behavior

Whatever is set during build environment install process it will be overridden to development

Possible Solution

Steps to Reproduce

  1. Pull samples/web-servers/react-frontend-sample
  2. pack build --clear-cache paketo-demo-app --builder paketobuildpacks/builder-jammy-base
  3. Logs for buildpack for NPM install 1.4.0 show following:
    Configuring build environment NODE_ENV -> "development" PATH -> "$PATH:/layers/paketo-buildpacks_npm-install/build-modules/node_modules/.bin"

Motivations

First of all I am a devops so this isn't really my cup of tea. So this is an issue my team has run into while using vite where the front builds and its throwing them errors. Whatever we do in nginx.toml it still uses the NODE_ENV=development. In the buildpack source code I found an override that always overwrites the variable you set with development I could be wrong but don't have many ideas left. I've tried locally to append env variable to 'pack build ' using --env but it does nothing.

This is the line of code I am suspecting is the issue. layer.BuildEnv.Override("NODE_ENV", "development") located here

layer.BuildEnv.Override("NODE_ENV", "development")

@Lancelot0105
Copy link

Hey @MilosMoravac , did you find any workaround for this issue ?

@c0d1ngm0nk3y
Copy link
Contributor

The original reason for this seems that the dev_dependencies should be available for the other buildpacks during build (see comment). Overwriting the user input feels wrong.

@c0d1ngm0nk3y
Copy link
Contributor

c0d1ngm0nk3y commented Sep 5, 2024

After digging a bit deeper into the code, I don't think the problem is

layer.BuildEnv.Override("NODE_ENV", "development")

but rather

return process.Run(layer.Path, npmCacheLayer.Path, projectPath, globalNpmrcPath, false)

which will call process.Run always with launch=false and then

environment = append(environment, "NODE_ENV=development")
will be added.

The "problem" is that this is by intention. It will always install the dev_dependencies for the build_modules and use npm prune for the launch_modules which will remove the dev_dependencies I think.

@MilosMoravac
Copy link
Author

MilosMoravac commented Sep 5, 2024

Hey @MilosMoravac , did you find any workaround for this issue ?

So in our pipeline when we build the image using packeto we set --env NODE_ENV="production" and that fixed it for us

@Lancelot0105
Copy link

@MilosMoravac Even I tried explicitly setting the NODE_ENV="production" but still during the build time it is building with NODE_ENV as "development". Could you please share the command and logs which made you get the production NODE_ENV ? We are stuck with this blocker for a really long time and would really like a solution/workaround for this.

@jwhitcraft
Copy link

Yeah this is biting us as well. We've had to restort to doing this in our package.json files:

{
  "scripts": {
    "build": "NODE_ENV=production vite build",
  }
}

@MilosMoravac
Copy link
Author

@MilosMoravac Even I tried explicitly setting the NODE_ENV="production" but still during the build time it is building with NODE_ENV as "development". Could you please share the command and logs which made you get the production NODE_ENV ? We are stuck with this blocker for a really long time and would really like a solution/workaround for this.

Sorry for late reply, we added --env NODE_ENV="production" to docker run buildpacksio/pack and it worked after that image was built.

@MilosMoravac MilosMoravac closed this as not planned Won't fix, can't repro, duplicate, stale Oct 3, 2024
@MilosMoravac MilosMoravac reopened this Oct 3, 2024
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

4 participants