-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Add option to not use node_modules layer at launch, for apps which bundle all dependencies into their output.
Describe the Enhancement
Currently, the buildpack node-start will always add a dependency on launch for node_modules. This means that these must be present in the image even though they are unusued.
Possible Solution
Introduce a new environment variable eg BP_NPM_LAUNCH_REQUIRES_MODULES which would be true by default (the current behaviour) but could be set to false to not add a launch requirement on node_modules layer.
This specific line of code would only be run if BP_NPM_LAUNCH_REQUIRES_MODULES is not false:
https://github.com/paketo-buildpacks/node-start/blob/main/detect.go#L39
This would then prevent this section of code being run in npm-install buildpack:
https://github.com/paketo-buildpacks/npm-install/blob/main/build.go#L236-L366
Motivation
For some apps, there is no dependency on the node_modules folder after the app is built. An example of this is nuxt, which ensures all dependencies including node modules are in the output folder.
Removing this layer from the output image should significantly reducing the image size. As an example the node_modules of a project I am working on is just short of 493MB in size, whereas the bundled app is 20MB.
It also removes an unexpected behaviour when using paketo-buildpacks/source-removal as removing node_modules/ folder causes it to throw error:
2025/08/11 00:58:05 readlink /workspace/node_modules: no such file or directory
ERROR: failed to launch: exec.d: failed to execute exec.d file at path '/layers/paketo-buildpacks_npm-install/launch-modules/exec.d/0-setup-symlinks': exit status 1
An example of the /workspace after building nuxt looks like:
package.jsonnode_modules/**/*nuxt.config.tssrc/- ...
.output/public/server/index.mjs<-- Entrypointpackage.json<-- Generated by nuxtnode_modules/**/*chunks/**/*