Issue
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
Solution
Given that you are running v21.x I assume you compiled and installed your own node. require('fs/promises')
is a relatively new addition, if you built node
into the /usr/local
path (which I think is default) it would explain all your symptoms.
Running node start.js
would use the the executable at /usr/local/bin/node
and be fine since it's on version 21.x; while adding the /usr/bin/node
shebang would fail since it's on an older version from the Debian repo that does not support the require('fs/promises')
call.
You can verify this by running which node
in the terminal to check where the executable you're running with node start.js
is located.
Also, there's no reason the symlink should cause a failure, I imagine you would get the same result by just trying to run ./start.js
.
Answered By - leitning Answer Checked By - Mildred Charles (WPSolving Admin)