Skip to content

Conversation

@sumomo015
Copy link

@sumomo015 sumomo015 commented Dec 24, 2025

Description

Fixes #792

This PR resolves an issue where the postinstall script fails when using package managers other than Yarn (such as pnpm or npm) in environments where Yarn is also installed globally.

Problem

The current postinstall script in npm/postinstall.js attempts to detect the package manager being used, but fails to properly identify non-Yarn package managers when Yarn is installed globally. This causes the installation to fail with errors when users try to install postman-code-generators using pnpm or npm.

Solution

Set the INIT_CWD environment variable during package manager detection to ensure the script correctly identifies the package manager being used, regardless of whether Yarn is installed globally.

Reproduction Steps (Before Fix)

  1. Create a Dockerfile with the following content:
FROM node:24.12.0

RUN npm install -g pnpm@10.26.2
RUN npm install -g yarn || true

WORKDIR /app

RUN pnpm init
# For demonstration only—enables 'dangerously-allow-all-builds', which is unsafe in production.
RUN echo "dangerously-allow-all-builds=true" >> .npmrc

# This step is expected to fail
RUN pnpm add postman-code-generators

CMD [ "echo", "Setup Complete" ]
  1. Run the following command to build:
docker build -t bug .

Result: The build fails when trying to install postman-code-generators with pnpm.

@sumomo015 sumomo015 changed the title Fix yarn postinstall failure by setting INIT_CWD for package manager detection Fix postinstall script to support non-Yarn package managers Dec 24, 2025
@sumomo015
Copy link
Author

As English is not my native language, this PR description was generated with the assistance of AI.

@sumomo015 sumomo015 marked this pull request as ready for review December 24, 2025 13:10
Copilot AI review requested due to automatic review settings December 24, 2025 13:10
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes an issue where the postinstall script fails to correctly detect the package manager when using pnpm or npm in environments where Yarn is also installed globally. The fix ensures proper package manager detection by passing the INIT_CWD environment variable to the detect() function.

  • Reads the INIT_CWD environment variable to capture the initial working directory
  • Passes the cwd option to the package manager detection function for accurate identification
Comments suppressed due to low confidence (1)

npm/deepinstall.js:28

  • Missing error handling for the promise rejection. If the detect() function fails, the promise rejection will not be caught, leaving the script hanging or causing an unhandled promise rejection. Add a .catch() handler to properly handle errors and call next() with the error.
    detect({ cwd: initCwd }).then((res) => {
      pm = res;
      console.log('Detected package manager: ' + pm);
      return next();
    });

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Successfully merging this pull request may close these issues.

Cant be used with non-yarn package managers and when yarn is also installed

1 participant