The error is coming because the project is setup to use pnpm
. But what I want is to display a suitable message to the user to let them know that they have to use pnpm
instead of npm
or yarn
.
I have tried to add preinstall script but the issue is somehow the command npm i
is running the workspace command on top and displaying this message:
*npm error code EUNSUPPORTEDPROTOCOL
npm error Unsupported URL Type "workspace:": workspace:*
npm error A complete log of this run can be found in: /home/lucifer/.npm/_logs/2024-10-20T16_20_28_424Z-debug-0.log*
Any way I can display a custom message to user?
You might have to leverage npm
‘s lifecycle scripts to check if npm
or yarn
is being used and display an error message.
Please take some time to go with below:
- Open your
package.json
. - Add a
preinstall
script that checks ifpnpm
is being used.
{
"scripts": {
"preinstall": "node check-pnpm.js"
}
}
- Create
check-pnpm.js
at the root.
const isPnpm = process.env.npm_config_user_agent && process.env.npm_config_user_agent.includes('pnpm');
if (!isPnpm) {
console.error('x1b[31m%sx1b[0m', 'ERROR: This project uses pnpm as the package manager. Please use pnpm instead of npm or yarn.');
process.exit(1); // Exit with failure
}
- If you run
npm install
oryarn install
, the script will stop the installation process and display the custom error message. - If you run
pnpm install
, it will proceed as usual without any issues.
1