How to fix storage/no-default-bucket: No bucket set in Firebase config in Firebase
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.
Quick fix
Fixes storage/no-default-bucket: No bucket set in Firebase config
// 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);- Locate your Firebase Storage bucket name
- Add storageBucket to your Firebase config
- Verify with environment variables (if applicable)
- Test Storage initialization
// 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 linemessagingSenderId: "123456789",appId: "YOUR_APP_ID"};const app = initializeApp(firebaseConfig);const storage = getStorage(app);storage/no-default-bucket: No bucket set in Firebase config
What this error means
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.
Typical symptoms
- Firebase Storage methods throw "storage/no-default-bucket" error
- getStorage() or firebase.storage() calls fail immediately
- File upload or download operations cannot initialize
- Error message asks "Did you set the storageBucket property when initializing the app?"
- Storage works in one environment but fails in another (staging vs production)
Common causes
- Missing storageBucket property in Firebase initialization config
- Empty string provided for storageBucket value
- Cloud Storage not enabled in Firebase Console for your project
- Using an incomplete or outdated Firebase config object
- Environment variable for storageBucket not set or incorrectly named
- Copying Firebase config from a project that never enabled Storage
How to fix "storage/no-default-bucket: No bucket set in Firebase config"
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.
Advanced notes
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.
Frequently asked questions
- What does "storage/no-default-bucket: No bucket set in Firebase config" mean?
- 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.
- How do I fix "storage/no-default-bucket: No bucket set in Firebase config"?
- 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.
- What causes "storage/no-default-bucket: No bucket set in Firebase config"?
- Missing storageBucket property in Firebase initialization config Empty string provided for storageBucket value Cloud Storage not enabled in Firebase Console for your project
- Is the "storage/no-default-bucket: No bucket set in Firebase config" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- ๐Firebase Official Documentation
- ๐firebase.google.com - start(Official Docs)
- ๐firebase.google.com - start(Official Docs)
- ๐github.com - 308(GitHub)
- ๐
- ๐github.com - 8123(GitHub)