Running soft linked node script as cmd. can’t find installed modules

I have a node script that running perfect inside the same project folder let’s say start.js that uses the puppeteer library and it’s running perfect as the following :
node start.js

what I’m trying to do is linking this command to use it anywhere inside the server

chmod +x /var/www/wc-service/spa/start.js && ln -s /var/www/wc-service/spa/bin/start.js /usr/bin/mycommand

but when running the new command from the bash, I got this error
Error: Cannot find module ‘fs/promises’ from inside node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserFetcher.js:36:20)

Notes

node: v21.1.0
Debian GNU/Linux 11
npm : 10.2.3

node is updated and have ‘fs/promises’ by default
any would be appreciated, Thanks

  • You’re chmodding it to be executable before the link, how are you running it without the link? By calling node start.js? Is there a shebang in start.js?

    – 

  • @leitning yes by calling node start.js and yes there is a shebang (#!/usr/bin/node ) in start.js

    – 

Leave a Comment