M-Zuber / npm-watch

run npm scripts when files change

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

npm-watch fails with ENOENT, unhandled error event in a hoisted lerna repository

tkalmar opened this issue · comments

I have a lerna monorepo in hoisted setup. npm-watch is installed in one of the child projects as devDependency
When running npm-watch the nodemon binary is not found
The problem is that:
$cwd/node_modules/.bin does not contain the binary but $cwd/../node_modules/.bin does. Experimenting a little bit i think the culprit is child_process.spawn which not recurses the node_modules directories. child_process.exec finds the binary

As a workaround nodemon can be installed globaly.

npm-watch version: 0.9.0
node version: 12.22.1

The issue with using child_process.exec is the buffering of the output (a stackoverflow answer with a drop more detail on the differences.

I will make a section in the Readme calling out this case.

Hey @M-Zuber, coming back on this discussion, it turns out that explicitly installing nodemon as a dev dependency fixed the issue for me.

I'm using a monorepo with PNPM and npm-watch is installed inside a sub-package.

repo/
|__apps/
|__packages/
  |__styles/
    package.json

package.json with an explicit dependency to nodemon.

"devDependencies": {
+  "nodemon": "^2.0.21",
  "npm-watch": "^0.11.0",
}

I don't know how and why it's fixing this issue but this might be worth to run some tests.

In my case, I prefer to avoid installing packages globally.