部署Firebase云函数时npm报错:missing script: lint
Hey there, let's get this sorted out quickly! The error you're hitting is straightforward: your Firebase Functions project's package.json doesn't have a lint script defined, but Firebase's predeploy process is trying to run it via the command npm --prefix "$RESOURCE_DIR" run lint. That's why you're seeing the non-zero exit code error stopping your deploy.
Here's exactly what you need to do:
Open your
package.jsonfile (it lives in yourfunctionsdirectory). You mentioned your scripts section currently looks like this:"scripts": { "serve": "firebase serve --only functions" }Add the
lintscript to thescriptsobject. You have two solid options here:Option 1: Set up proper linting (recommended for long-term)
First, install ESLint (the most widely used linting tool for JavaScript/TypeScript projects) in your functions directory:cd functions npm install eslint --save-devThen update your
package.jsonscripts to include the lint command:"scripts": { "serve": "firebase serve --only functions", "lint": "eslint ." }This will run ESLint across all your function files to catch code quality issues, syntax errors, and style inconsistencies.
Option 2: Temporarily bypass linting (quick fix only)
If you just need to push your deploy through right now, you can add a dummy lint script that does nothing:"scripts": { "serve": "firebase serve --only functions", "lint": "echo 'Skipping linting temporarily'" }Heads up: This skips important code checks, so don't rely on this for production projects.
Test the script first to make sure it works before redeploying:
npm --prefix "$RESOURCE_DIR" run lintIf you set up ESLint, it will output any linting errors/warnings. If you used the dummy script, it should just print your message without errors.
Redeploy your functions – the predeploy error should now be resolved.
A quick note on why this happens:
Firebase's default predeploy configuration for Cloud Functions includes a lint check step. It expects your package.json to have a lint script defined, so when it can't find one, it throws the "missing script: lint" error and halts the deploy process.
内容的提问来源于stack exchange,提问作者rakesh patel

