Running ‘npm install’ unexpectedly invokes the prepublish script. For example, consider this modified package configuration:
{
"name": "bar",
"version": "0.0.1",
"scripts": {
"prepublish": "echo 'Executing pre-publish routines'"
},
"dependencies": {
"underscore": "^1.9.1"
}
}
When executing npm install, the prepublish script runs. Is this intended, and how can it be avoided?
hey, its expected. older npm versions run prepublish on install. switching to prepublishOnly or update npm can help so it only runs during publishing.
In my experience, this behavior is due to an older version of npm where the prepublish script was also triggered during installation. When working on multiple projects, I noticed that updates to npm resolve this by changing the behavior so that prepublish only runs at publish time. A practical solution has been to either update npm or adapt the script to use prepublishOnly, which avoids unexpected script executions during an npm install. This change mitigated confusion in several of my projects and has provided a more predictable workflow over time.