Firebase Functions部署失败:提示缺少build脚本
Hey there! I’ve run into this exact issue before when getting started with Firebase Functions, so let’s walk through how to fix it step by step.
What’s causing this error?
The error means your Firebase Functions project’s package.json file doesn’t have a build script defined in its scripts section. Firebase looks for this script during deployment to prepare your code for production—most commonly, compiling TypeScript to JavaScript if you’re using TypeScript, which matches the tutorial you’re following.
How to fix it:
Navigate to your Functions directory
In your project root, head to thefunctionsfolder—this is where yourpackage.jsonfile lives.Open the
package.jsonfile
Look for the"scripts"object. It might look like this if you’re missing the build script:"scripts": { "serve": "firebase emulators:start --only functions", "shell": "firebase functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }Add the
buildscript
Since the tutorial uses TypeScript, add this line inside thescriptsobject—it tells npm to run the TypeScript compiler to convert your.tsfiles to runnable.jscode:"build": "tsc"Your updated
scriptssection should look like this:"scripts": { "build": "tsc", "serve": "firebase emulators:start --only functions", "shell": "firebase functions:shell", "start": "npm run shell", "deploy": "firebase deploy --only functions", "logs": "firebase functions:log" }If you’re using plain JavaScript (unlikely for this tutorial), you can add a dummy build script if Firebase still expects it:
"build": "echo 'No build required for JavaScript'"Save the file and re-run deployment
Runfirebase deploy --only functionsagain, and the error should be resolved.
Quick troubleshooting if you’re still stuck:
- Did you initialize your Functions project with TypeScript? If not, re-run
firebase init functionsand select TypeScript when prompted to set up the necessary tooling. - Double-check the tutorial’s sample
package.json—you might have missed copying the build script from the provided example.
内容的提问来源于stack exchange,提问作者strypeez

