angularfire: Build error: This module is declared with using 'export ='
After updating to v6.0.4 from v6.0.3 I am getting the following error - This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
Setting allowSyntheticDefaultImports: true
gives the following error:
ERROR in node_modules/@angular/fire/storage/observable/fromTask.d.ts:3:83 - error TS2694: Namespace 'firebase' has no exported member 'default'.
3 export declare function fromTask(task: UploadTask): Observable<import("firebase").default.storage.UploadTaskSnapshot>;
~~~~~~~
Version info
Angular:
10.2.1
Firebase:
7.24.0
AngularFire:
6.0.4
How to reproduce these conditions
Steps to set up and reproduce
Update to 6.0.4
Debug output
N/A
Log stack
ERROR in node_modules/@angular/fire/firebase.app.module.d.ts:2:8 - error TS1259: Module '"/Users/akshayrajgollahalli/Documents/GitHub/lectus-ui/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
2 import firebase from 'firebase/app';
~~~~~~~~
node_modules/firebase/index.d.ts:9710:1
9710 export = firebase;
~~~~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/auth-guard/auth-guard.d.ts:4:8 - error TS1259: Module '"/Users/akshayrajgollahalli/Documents/GitHub/lectus-ui/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
4 import firebase from 'firebase/app';
~~~~~~~~
node_modules/firebase/index.d.ts:9710:1
9710 export = firebase;
~~~~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/auth/auth.d.ts:4:8 - error TS1259: Module '"/Users/akshayrajgollahalli/Documents/GitHub/lectus-ui/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
4 import firebase from 'firebase/app';
~~~~~~~~
node_modules/firebase/index.d.ts:9710:1
9710 export = firebase;
~~~~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/auth/auth.d.ts:12:14 - error TS2411: Property 'authState' of type 'Observable<any>' is not assignable to string index type 'Promise<any> & ((...args: unknown[]) => Promise<any>) & ((...args: unknown[]) => any)'.
12 readonly authState: Observable<firebase.User | null>;
~~~~~~~~~
node_modules/@angular/fire/auth/auth.d.ts:16:14 - error TS2411: Property 'idToken' of type 'Observable<string>' is not assignable to string index type 'Promise<any> & ((...args: unknown[]) => Promise<any>) & ((...args: unknown[]) => any)'.
16 readonly idToken: Observable<string | null>;
~~~~~~~
node_modules/@angular/fire/auth/auth.d.ts:20:14 - error TS2411: Property 'user' of type 'Observable<any>' is not assignable to string index type 'Promise<any> & ((...args: unknown[]) => Promise<any>) & ((...args: unknown[]) => any)'.
20 readonly user: Observable<firebase.User | null>;
~~~~
node_modules/@angular/fire/auth/auth.d.ts:26:14 - error TS2411: Property 'idTokenResult' of type 'Observable<any>' is not assignable to string index type 'Promise<any> & ((...args: unknown[]) => Promise<any>) & ((...args: unknown[]) => any)'.
26 readonly idTokenResult: Observable<firebase.auth.IdTokenResult | null>;
~~~~~~~~~~~~~
node_modules/@angular/fire/firestore/interfaces.d.ts:2:8 - error TS1259: Module '"/Users/akshayrajgollahalli/Documents/GitHub/lectus-ui/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
2 import firebase from 'firebase/app';
~~~~~~~~
node_modules/firebase/index.d.ts:9710:1
9710 export = firebase;
~~~~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/firestore/collection/collection.d.ts:2:8 - error TS1259: Module '"/Users/akshayrajgollahalli/Documents/GitHub/lectus-ui/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
2 import firebase from 'firebase/app';
~~~~~~~~
node_modules/firebase/index.d.ts:9710:1
9710 export = firebase;
~~~~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/firestore/document/document.d.ts:5:8 - error TS1259: Module '"/Users/akshayrajgollahalli/Documents/GitHub/lectus-ui/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
5 import firebase from 'firebase/app';
~~~~~~~~
node_modules/firebase/index.d.ts:9710:1
9710 export = firebase;
~~~~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/firestore/collection-group/collection-group.d.ts:2:8 - [39m[91merror TS1259: Module '"/Users/akshayrajgollahalli/Documents/GitHub/lectus-ui/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
2 import firebase from 'firebase/app';
~~~~~~~~
node_modules/firebase/index.d.ts:9710:1
9710 export = firebase;
~~~~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/firestore/firestore.d.ts:9:8 - error TS1259: Module '"/Users/akshayrajgollahalli/Documents/GitHub/lectus-ui/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
9 import firebase from 'firebase/app';
~~~~~~~~
node_modules/firebase/index.d.ts:9710:1
9710 export = firebase;
~~~~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/storage/interfaces.d.ts:1:8 - error TS1259: Module '"/Users/akshayrajgollahalli/Documents/GitHub/lectus-ui/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
1 import firebase from 'firebase/app';
~~~~~~~~
node_modules/firebase/index.d.ts:9710:1
9710 export = firebase;
~~~~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/storage/storage.d.ts:6:8 - error TS1259: Module '"/Users/akshayrajgollahalli/Documents/GitHub/lectus-ui/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
6 import firebase from 'firebase/app';
~~~~~~~~
node_modules/firebase/index.d.ts:9710:1
9710 export = firebase;
~~~~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/storage/observable/fromTask.d.ts:3:83 - error TS2694: Namespace 'firebase' has no exported member 'default'.
3 export declare function fromTask(task: UploadTask): Observable<import("firebase").default.storage.UploadTaskSnapshot>;
~~~~~~~
node_modules/@angular/fire/analytics/analytics.d.ts:3:8 - error TS1259: Module '"/Users/akshayrajgollahalli/Documents/GitHub/lectus-ui/node_modules/firebase/index"' can only be default-imported using the 'allowSyntheticDefaultImports' flag
3 import firebase from 'firebase/app';
~~~~~~~~
node_modules/firebase/index.d.ts:9710:1
9710 export = firebase;
~~~~~~~~~~~~~~~~~~
This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.
node_modules/@angular/fire/analytics/analytics.d.ts:17:5 - error TS2411: Property 'updateConfig' of type '(config: Config) => Promise<void>' is not assignable to string index type 'Promise<any> & ((...args: unknown[]) => Promise<any>) & ((...args: unknown[]) => any)'.
17 updateConfig(config: Config): Promise<void>;
~~~~~~~~~~~~
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 11
- Comments: 30 (5 by maintainers)
I see…
What happens when you add these entries to
compilerOptions
in tsconfig?Can confirm that @angular/fire 6.0.5 and firebase@8.0.1 no longer receives the error, my solution was simply
npm install firebase@latest
Ok I did a bit of digging and it seems the problem is not the angularfire rather the firebase library itself.
if you need to import firebase anywhere into your angularfire project, the firease.[whatever] is not accessible in the new versions anymore. The path has changed but it seems guys @Google forgot to update the documentations.
Here is an example. Let’s say you have this in your imports:
import * as firebase from 'firebase/app';
Now if you try to access anything inside
firebase
as usual it will throw the error messages you shared above. For example this:return firebase.firestore.FieldValue.serverTimestamp()
will return an error. You have to add
default
to the namespace - in firebase 7.x.x and 8.x.x - in order to make it work:return firebase.default.firestore.FieldValue.serverTimestamp();
that applies everywhere you are referring to
firebase
in your code.+1 same result as @gbrits - all good after upgrade to
@angular/fire@6.0.5
andfirebase@8.0.1
also worth checking…
Do you have this import command:
import * as firebase from 'firebase/app'
anywhere in your components, services, …?
+1 confirm
firebase@8.0.1
works like a charm!Setting
"allowSyntheticDefaultImports": true
undercompilerOptions
in mytsconfig.json
has resolved the issue for me.My
package.json
included:I really dislike the proposed fix (
allowSyntheticDefaultImports
/esModuleInterop
), it feels like a patch. I went on a hunt and figured out a solution that works better for me and might work better for you guys. Before simply copy pasting my code, here is how I came to this fix; if you’re not interested just scroll down 👇 For those that read this, please point out any potential problems with this approach 👍If you have a look at the firebase sdk js release notes here you will find the following breaking change
With this information, I decided to upgrade to
firebase
v8 (8.2.2
) after my upgrade ofangular/fire
to6.1.4
despite the recommendation to be on firebasev7.8
in the readme of this repository. I did this because the problem is obviously an importing problem, I decided to change my import statements to match firebase documentation recommendation. Which looks like thisimport firebase from 'firebase/app';
This introduced the problem of types I was using, as I was importing firestore as a type
The solution is quite simple in retrospect, using the new import and accessing firestore on the firebase global namespace
If you’re using the firestore namespace a lot in your code, suffixing it with
firebase
can be annoying and can reduce readability. To mitigate this I use the following namespace aliasing trick, this will ensure your code changes only affect yourimport
statements. See namespace aliasing in the official typescript documentation here if this syntax is unfamiliar to youEDIT: Sorry for pinging you all. It was an issue with TS not picking the new version. After I ctrl+clicked it and fell through it stopped showing the error.
ORIGINAL MESSAGE: I just tried upgrading from
@angular/fire@6.0.3
andfirebase@7.14.1
to latest (6.1.1 and 8.1.1) and I’m seeing this issue."allowSyntheticDefaultImports": true
helps but reading this thread I’m not sure I’m supposed to do it like that…Bumping a major isn’t trivial with a library with the popularity of AngularFire, it means there’s a very large chance of leaving users behind & unsupported as I only have the resources to support the latest major (on a best-effort basis at that). With a large rewrite of the Firebase JS SDK coming & new Angular majors on the way, I’d rather leave a breaking version for that. Which is why I sometimes do back flips to support multiple Angular/Firebase majors 😛
Firebase v8 doesn’t export a namespace anymore, you should use the default export.
Oh only
import firebase from 'firebase/app'
and then usefirebase.firestore
in your code.