node.js - why package.json script works fine on local project but doesn't work on a dependency project -
i have created npm module(let call modulea
) , defined clean
script in package.json file below:
"scripts": { "test": "nyc mocha tests/ --opts mocha.opts", "build": "babel -d dist/ src/", "prepublish": "yarn run clean && yarn run build", "postinstall": "yarn run clean && yarn run build", "clean": "rimraf ./dist" },
i use rimraf
remove dist
directory. dependency defined in devdependencies
"rimraf": "^2.6.1"
. works fine on project. in 1 of other project (let call moduleb
) has dependency on module, yarn install
doesn't work , below error:
$ rimraf ./dist sh: 1: rimraf: not found
this error happens when npm/yarn
building moduleb
. have checked rimraf
exist in node_modules/.bin
directory in moduleb
. works fine if install rimraf
globally. wonder how can make npm/yarn use rimraf
node_modules/.bin/rimraf
?
btw, put rimraf
in devdependencies
in moduleb
.
i tried update script in modulea
use rimraf
node_modules/.bin/rimraf
below:
"clean": "node_modules/.bin/rimraf ./dist"
it works fine on modulea
. got below error when run yarn install
on moduleb
:
$ node_modules/.bin/rimraf ./dist info visit https://yarnpkg.com/en/docs/cli/run documentation command. sh: node_modules/.bin/rimraf: no such file or directory error command failed exit code 127.
see issues:
- https://github.com/yarnpkg/yarn/issues/721 (postinstall hook doesn't appear run #721)
- https://github.com/yarnpkg/yarn/issues/853 (preinstall , postinstall not run #853)
- https://github.com/yarnpkg/yarn/issues/614 (bug: issue postinstall scripts in git-hooks package)
now make sure yarn clean
and npm clean
works expected.
for example not work if didn't install rimraf
globally:
$ rimraf ./dist
but should work:
$ ./node_modules/.bin/rimraf ./dist
test commands first:
npm run clean
and:
yarn run clean
to use "clean": "rimraf ./dist"
script defined in package.json.
note ./node_modules/.bin
added path
when run package.json scripts.
try running commands simple ones run script directly without npm
or yarn
, test both npm
and yarn
, , try narrow down problem postinstall hooks.
Comments
Post a Comment