Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module './commands/run-script.js' (Firebase CLI, npm, node.js)

I recently upgraded my system and I'm trying to compile a Firebase cloud functions project that used to work.

After running this:

firebase deploy --only functions

I get the following error:

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
npm ERR! code MODULE_NOT_FOUND
npm ERR! Cannot find module './commands/run-script.js'
npm ERR! Require stack:
npm ERR! - /snapshot/firepit/node_modules/npm/lib/npm.js
npm ERR! - /snapshot/firepit/node_modules/npm/lib/cli.js
npm ERR! - /snapshot/firepit/node_modules/npm/bin/npm-cli.js
npm ERR! 1) If you want to compile the package/file into executable, please pay attention to compilation warnings and specify a literal in 'require' call. 2) If you don't want to compile the package/file into executable and want to 'require' it from filesystem (likely plugin), specify an absolute path in 'require' call using process.cwd() or process.execPath.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/andrea/.npm/_logs/2023-09-22T14_40_37_566Z-debug-0.log

Error: functions predeploy error: Command terminated with non-zero exit code 1

The main issue seems to be this:

Cannot find module './commands/run-script.js'

This file is not part of my project and ChatGPT told me this:

./commands/run-script.js is not a file you should be concerned with creating or maintaining; it's internal to the npm package. If a reference to this internal npm file is causing issues, it typically indicates a problem with the npm installation itself.

I've tried reinstalling npm but without luck.

Some extra details:

  • my package.json file specifies node version 18
  • node -v outputs v18.17.1
  • npm -v outputs 9.6.7
  • firebase --version outputs 12.5.4

Here's a link to my error log:

https://gist.github.com/bizz84/38e969c705d06086403966833878a6a7

I can't seem to figure this out. Any ideas?

like image 622
bizz84 Avatar asked Oct 15 '25 16:10

bizz84


2 Answers

As it turns out, the problem was that I had installed the firebase-tools with the auto-install script:

curl -sL https://firebase.tools | bash

The fix was to remove them:

curl -sL firebase.tools | uninstall=true bash

And then reinstall them with npm:

npm install -g firebase-tools
like image 93
bizz84 Avatar answered Oct 18 '25 06:10

bizz84


It appears the firebase cli is not using your expected node / npm installation. It reported node v16.16.0 and npm v8.19.4 in the log file.

How did you install? Did you use curl -sL firebase.tools | bash? To make it easier to onboard user, I think the Firebase team is doing something unconventional here and download an entirely different node stack to run their tools...

As a workaround, you may install it locally in your project. Something like this:

# assuming you are working on this https://github.com/bizz84/flutter-firebase-masterclass
cd ./ecommerce_app/functions

# this will download the cli into ./node_modules/.bin/firebase
npm install --include=dev firebase-tools

# always use npm script or npx to use the local script
# running firebase deploy directly in your Terminal will use the global one
npm run deploy
like image 24
mrpaint Avatar answered Oct 18 '25 07:10

mrpaint



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!