porter icon indicating copy to clipboard operation
porter copied to clipboard

Porter watch won't work

Open calebdw opened this issue 2 years ago • 7 comments

Hello,

I installed chokidar globally per the docs, however, executing the porter watch command yields the following error:

Watcher process has terminated. Please ensure Node and chokidar are installed.

Executing npm list -g shows I have chokidar installed:

$ npm list -g
/usr/lib
├── @johnnymorganz/[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

calebdw avatar Jan 27 '23 17:01 calebdw

Im also seeing this, I believe that the watch node script can not import the global installed chokidar

Watcher process has terminated. Please ensure Node and chokidar are installed.
node:internal/modules/cjs/loader:1042
  throw err;
  ^

Error: Cannot find module 'chokidar'
Require stack:
- /Users/matt/.porter/file-watcher.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1039:15)
    at Module._load (node:internal/modules/cjs/loader:885:27)
    at Module.require (node:internal/modules/cjs/loader:1105:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/Users/matt/.porter/file-watcher.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1218:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
    at Module.load (node:internal/modules/cjs/loader:1081:32)
    at Module._load (node:internal/modules/cjs/loader:922:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ '/Users/matt/.porter/file-watcher.js' ]
}

Node.js v18.13.0

I'm on macOS if I go to ~/.porter in the directory with file-watcher.js and run npm install chokidar there things work as expected

dpslwk avatar Feb 01 '23 17:02 dpslwk

It seems your node path is not registered: https://nodejs.org/api/modules.html#loading-from-the-global-folders

PhiloNL avatar Feb 02 '23 11:02 PhiloNL

defining node path in my normal .zsenv did not help me since what ever environment porter is starting the watcher from does not pick that up

perhaps adding NODE_PATH=$(npm root --quiet -g) as an environment in porters [program:watcher] might work for everyone

dpslwk avatar Feb 02 '23 11:02 dpslwk

Also, NPM already searches the following GLOBAL paths:

Additionally, Node.js will search in the following list of GLOBAL_FOLDERS:

1: $HOME/.node_modules
2: $HOME/.node_libraries
3: $PREFIX/lib/node

However, explicitly setting the NODE_PATH variable has no effect on the error message.

calebdw avatar Feb 02 '23 12:02 calebdw

Are you sure this is also where chokidar got installed? I'm using nvm for example, and this path is not automatically loaded, for example, I have to export the following path for Porter to work:

export NODE_PATH=/Users/developer/.nvm/versions/node/v18.10.0/lib/node_modules

PhiloNL avatar Feb 03 '23 08:02 PhiloNL

It looks like it's installed there:

$ ll /usr/lib/node_modules/
total 44K
drwxr-xr-x  11 root root 4.0K Jan 27 11:46  ./
drwxr-xr-x 129 root root 4.0K Jan 24 09:07  ../
drwxr-xr-x   7 root root 4.0K Aug  2  2022  blade-formatter/
drwxr-xr-x   5 root root 4.0K Jan 27 11:46  chokidar/
drwxr-xr-x   4 root root 4.0K Jan 16 09:17  corepack/
drwxr-xr-x   7 root root 4.0K Jul 27  2022  eslint/
drwxr-xr-x   3 root root 4.0K Aug  2  2022 '@johnnymorganz'/
drwxr-xr-x   6 root root 4.0K Jul 25  2022  neovim/
drwxr-xr-x   3 root root 4.0K Aug  2  2022  nginxbeautifier/
drwxr-xr-x   7 root root 4.0K Jan 16 09:17  npm/
drwxr-xr-x   2 root root 4.0K Sep 10 08:32  tree-sitter-cli/

calebdw avatar Feb 03 '23 14:02 calebdw

I have the same issue as described above.

echo $NODE_PATH in the terminal shows the correct path. Executing npm list -g shows I have chokidar installed

Error message in watcher.log: Watcher process has terminated. Please ensure Node and chokidar are installed.

radermacher avatar Mar 29 '23 22:03 radermacher