This error occurs when Firebase Storage is initialized without specifying a storageBucket property. The fix involves adding your Cloud Storage bucket URL to the Firebase configuration object during initialization.
The "storage/no-default-bucket" error indicates that your Firebase app was initialized without providing the required storageBucket configuration property. Firebase Storage requires an explicit bucket name to know where to store and retrieve files. This bucket is essentially a Google Cloud Storage container that Firebase uses to manage your uploaded files. When you initialize Firebase, the SDK expects a configuration object containing various service URLs, including storageBucket. If this property is missing, empty, or invalid, any attempt to use Firebase Storage methods will immediately fail with this error. This commonly happens when developers copy incomplete Firebase config objects, forget to enable Cloud Storage in their Firebase project, or accidentally omit the storageBucket property when setting up environment variables.
Open the [Firebase Console](https://console.firebase.google.com/), select your project, and navigate to Storage in the left sidebar. If Storage is not enabled, click Get Started to enable it. Once enabled, you'll see your bucket name at the top of the page.
The bucket name will be in one of these formats:
- New projects (Oct 2024+): PROJECT_ID.firebasestorage.app
- Older projects: PROJECT_ID.appspot.com
Copy this bucket name (without the gs:// prefix).
Update your Firebase initialization code to include the storageBucket property:
// For modular SDK (v9+)
import { initializeApp } from "firebase/app";
import { getStorage } from "firebase/storage";
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "your-project.firebaseapp.com",
projectId: "your-project",
storageBucket: "your-project.appspot.com", // Add this line
messagingSenderId: "123456789",
appId: "YOUR_APP_ID"
};
const app = initializeApp(firebaseConfig);
const storage = getStorage(app);// For compat SDK (v8)
import firebase from "firebase/app";
import "firebase/storage";
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "your-project.firebaseapp.com",
projectId: "your-project",
storageBucket: "your-project.appspot.com", // Add this line
messagingSenderId: "123456789",
appId: "YOUR_APP_ID"
};
firebase.initializeApp(firebaseConfig);
const storage = firebase.storage();If you're using environment variables for Firebase config, ensure storageBucket is included:
# .env.local
NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=your-project
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789
NEXT_PUBLIC_FIREBASE_APP_ID=your_app_idThen reference it in your config:
const firebaseConfig = {
apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
storageBucket: process.env.NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.NEXT_PUBLIC_FIREBASE_APP_ID
};Restart your development server after updating environment variables.
Verify the fix by attempting a basic Storage operation:
import { getStorage, ref } from "firebase/storage";
try {
const storage = getStorage();
const storageRef = ref(storage, 'test/path');
console.log('Storage initialized successfully!', storageRef.bucket);
} catch (error) {
console.error('Storage error:', error.code, error.message);
}If successful, you should see your bucket name logged without any errors.
For projects using multiple Firebase Storage buckets, you can specify a non-default bucket explicitly when getting a storage reference:
import { getStorage } from "firebase/storage";
// Use a specific bucket instead of the default
const storage = getStorage(app, "gs://my-custom-bucket.appspot.com");In Firebase Admin SDK (Node.js server-side), the syntax differs slightly:
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.applicationDefault(),
storageBucket: 'your-project.appspot.com' // No gs:// prefix
});
const bucket = admin.storage().bucket();Security note: Ensure your Storage Security Rules are properly configured before deploying to production. The storageBucket configuration does not control access permissions - those are managed separately through Security Rules in the Firebase Console.
October 2024 bucket URL changes: Firebase introduced new bucket URLs with the .firebasestorage.app domain. Older projects still use .appspot.com. Both formats work, but you should use the bucket URL shown in your Firebase Console to avoid confusion. If you recently created your project and see a .firebasestorage.app URL, use that instead of the legacy .appspot.com format.
Callable Functions: INTERNAL - Unhandled exception
How to fix "Callable Functions: INTERNAL - Unhandled exception" in Firebase
auth/invalid-hash-algorithm: Hash algorithm doesn't match supported options
How to fix "auth/invalid-hash-algorithm: Hash algorithm doesn't match supported options" in Firebase
Hosting: CORS configuration not set up properly
How to fix CORS configuration in Firebase Hosting
auth/reserved-claims: Custom claims use reserved OIDC claim names
How to fix "reserved claims" error when setting custom claims in Firebase
Callable Functions: UNAUTHENTICATED - Invalid credentials
How to fix "UNAUTHENTICATED - Invalid credentials" in Firebase Callable Functions