-
Notifications
You must be signed in to change notification settings - Fork 986
Description
[REQUIRED] Describe your environment
Operating System version: macOS 11
Browser version: Safari 14
Firebase SDK version: 9
Firebase Product: all
[REQUIRED] Describe the problem
I am working with SvelteKit which uses Vite for bundling and I am not sure if it's the firebase "export * from '@firebase/app';" or if it's Vite. But when importing firebase like this "import { initializeApp } from 'firebase/app';" Vite says it's a commonjs package. If it's a dev depencency and trying to build it reports as followed:
> Named export 'initializeApp' not found. The requested module 'firebase/app' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'firebase/app';
const { initializeApp } = pkg;
For the dev server it works fine. When installing firebase as a normal dependency and running build everything works fine but when trying to run the dev server this error pops up:
12:45:52 [vite] Error when evaluating SSR module /node_modules/firebase/app/dist/index.cjs.js:
ReferenceError: exports is not defined
at eval (/node_modules/firebase/app/dist/index.cjs.js:5:23)
at instantiateModule (/Users/abdo/Downloads/svelte-firebase-error-master/node_modules/vite/dist/node/chunks/dep-cc49d7be.js:72639:166)
exports is not defined
ReferenceError: exports is not defined
at eval (/node_modules/firebase/app/dist/index.cjs.js:5:23)
at instantiateModule (/Users/abdo/Downloads/svelte-firebase-error-master/node_modules/vite/dist/node/chunks/dep-cc49d7be.js:72639:166)
Like I said I am not sure if it's because of the all export or if it's Vite but changing the "import { initializeApp } from 'firebase/app';" to "import { initializeApp } from '@firebase/app';" doesn't throw an error in both cases.