Skip to content

Add ability to remove dependency on node_modules at runtime #736

@ZephireNZ

Description

@ZephireNZ

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.json
  • node_modules/**/*
  • nuxt.config.ts
  • src/
    • ...
  • .output/
    • public/
    • server/
      • index.mjs <-- Entrypoint
      • package.json <-- Generated by nuxt
      • node_modules/**/*
      • chunks/**/*

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions