paketo-buildpacks / npm-install

A Cloud Native Buildpack for npm
Apache License 2.0
10 stars 17 forks source link

UI applications built by buildpacks is not using react production build #756

Open Lancelot0105 opened 2 months ago

Lancelot0105 commented 2 months ago

The UI applications built by buildpacks is not using build assets of react. Even though the NODE_ENV is setup during the build time, it is getting overwritten by npm-install buildpack.

Expected Behavior

NODE_ENV should not be overwritten by the npm-install buildpack

Current Behavior

NODE_ENV is getting overwritten by the npm-install buildpack.

Possible Solution

I believe if the code can be configured to use default NODE_ENV, this should work.

Steps to Reproduce

Build any UI application using the nodejs buildpack, see the NODE_ENV which is getting assigned during npm-install buildpack.

Motivations

In a world of CI/CD, in the production environment the basic necessity of any built application is to use the Production asset of the tool. Using a development build contradicts the whole purpose.

I believe a similar issue was raised here:

@andymoe @nebhale @anthonydahanne @ryanmoran

AshwinSridharan0410 commented 2 months ago

Hi @Lancelot0105 , I too face this issue and would like to know the solution here.

As rightly said, if the image built with buildpacks goes into production , it shows me that I am seeing a development build of react.

image

The ideal case should be :- image

swathika1 commented 2 months ago

@Lancelot0105 , I'm experiencing the same issue and would appreciate any support here

c0d1ngm0nk3y commented 2 months ago

It was introduced with https://github.com/paketo-buildpacks/npm-install/commit/04b8c7d739f6802fb3be8a5971b8c06fd40678cf

If the modules are required at build time a separate layer will be created that will install node_modules with the same logic as setting NODE_ENV=development meaning all devDependencies will be available for subsequent buildpacks to access. However only dependencies that conform to the default or user set NODE_ENV will make it onto the final running image.

So we have conflicting requirements here, right? We want to install dev_dependencies for the following buildpacks and use NODE_ENV=production for react.

see this comment for details.

Lancelot0105 commented 1 month ago

@c0d1ngm0nk3y But even though the end artifact is running with the development build environment of react right ? Which shouldn't be happening so.