Closed CheezeCoder closed 6 years ago
I'm not 100% sure, but I don't think the @firebase
packages are meant for public usage. Perhaps just changing import '@firebase/...'
to import 'firebase/...'
will fix the issue?
Yeah I figured that might be the case.. but it doesn't seem to have any effect at all. I still get the same warnings :(
Not 100% sure if it'll solve your issue, but I got your stackblitz working (https://stackblitz.com/edit/firebase-issue-sandbox-hhbeye). Basically I:
import * as firebase from 'firebase'
to import firebase from 'firebase'
@firebase
to firebase
Awesome. Thanks. I’ll check it out when I get back. Am away for the weekend.
Back now. @mikelehen Ive updated my firebase from 5.1 to 5.2 (didn't realize i was behind :/). Ive created a new stackblitz as I'm using typescript so import firebase from 'firebase'
in this case won't work. Im still stuck as even updating my project to 5.2 and using the firebase packages sans '@' still results in the same problems :/ here the new stackblitz with typescript:
https://stackblitz.com/edit/react-ts-dvv5fy?file=index.tsx
Any ideas? What strikes me the most weird is the
WARNING in ./app/stores/FirebaseStore.ts 16:10-32
"export 'initializeApp' (imported as 'firebase') was not found in 'firebase/app'
That I get..,.. its like its not working to import them :/ I don't know why.... maybe something to do with my typescript config and not firebase??
{
"compilerOptions": {
"sourceMap": true,
"target": "es5",
"jsx": "react",
"module": "es6",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"declaration": false,
"noImplicitAny": false,
"noImplicitReturns": false,
"keyofStringsOnly": true,
"noUnusedLocals": true,
"removeComments": true,
"strictNullChecks": false,
"outDir": "build",
"lib": ["es6", "es7", "dom"],
"baseUrl": "src",
"paths": {
"app/*": ["./app/*"]
}
},
"exclude": ["dist", "build", "node_modules"]
}
Looks like you missed this step:
import * as firebase from 'firebase'
to import firebase from 'firebase'
It should still work like that. What error does it give when you try this?
Edit: Also, the recommended way is to do this:
import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';
@mmermerkaya That won't compile with typescript.
Can you provide an error message?
@mmermerkaya
✖ 「atl」: Checking finished with 1 errors ✖ 「wdm」: 690 modules
ERROR in [at-loader] ./src/app/stores/FirebaseStore.ts:1:8
TS1192: Module '"C:/Development/WeddingClient/node_modules/firebase/index"' has no default export.
ℹ 「wdm」: Failed to compile.
You should add "esModuleInterop": true
to your tsconfig.json
. TypeScript team "highly recommends applying it both to new and existing projects". See TS 2.7 release notes for more information (search for "esModuleInterop", it's close to the bottom of the page).
If it still doesn't work, try changing "module": "es6"
to "module": "commonjs"
in your TSConfig.
@mmermerkaya Interesting. Changing the mode to commonjs
seems to work! Hallelujah! This with having my imports as import * as firebase from 'firebase'
still though and NOT including esModuleInterop
. However if I leave my mode at es6
with mode at es6 and DO include esModuleInterop
and try import to a standard import import firebase from 'firebase'
I get an error
✖ 「atl」: Checking finished with 1 errors ✖ 「wdm」: 690 modules
ERROR in [at-loader] ./src/app/stores/FirebaseStore.ts:1:8
TS1192: Module '"C:/Development/WeddingClient/node_modules/firebase/index"' has no default export.
ℹ 「wdm」: Failed to compile.
So it seems the module dictates the problem here as it seems to be irrelevant of whether esModuleInterop
is true or not.
Now... if I I leave module at es6 and DO include both esModuleInterop
and allowSyntheticDefaultImports
as true it COMPILES!
To summarize:
{ "compilerOptions": { "module": "commonjs" }}
=> COMPILES
{ "compilerOptions": { "module": "es6", "esModuleInterop": true, }}
=> FAILS
{ "compilerOptions": { "module": "es6", "esModuleInterop": true, "allowSyntheticDefaultImports": true, }}
=> COMPILES
{ "compilerOptions": { "module": "commonjs", "esModuleInterop": true, }}
=> COMPILES
{ "compilerOptions": { "module": "commonjs", "esModuleInterop": true, "allowSyntheticDefaultImports": true, }}
=> COMPILES
What's really frustrating is that regardless of what my .tsconfig file is set at VS Code gives me an error in the editor even though it compiles :
:(
I wish I understood all of this a bit better.
{ "compilerOptions": { "module": "es6", "esModuleInterop": true, }} => FAILS { "compilerOptions": { "module": "es6", "esModuleInterop": true, "allowSyntheticDefaultImports": true, }} => COMPILES
That is really weird, because unless you're explicitly disabling it, enabling esModuleInterop
should also enable allowSyntheticDefaultImports
by default. :confused: See its definition here.
AFAIK, changing module to "commonjs"
delegates all module resolution to Webpack, and Webpack knows how to find and import submodules better than TypeScript.
VSCode usually needs a restart when you change TSConfig settings. I created a tiny project to test it and it seems to work on my machine.
Also you should import firebase from 'firebase/app'
, not from 'firebase' :slightly_smiling_face:
@mmermerkaya Yeah, a lot of this stuff is over my head. However seeing as how things are playing nicely with the current typescript syntax import * as A from 'A'
, i think ill just go with the "mode": "commonjs"
route for the moment. Ill have to spend some time reading up on the compilerOptions
a bit more when I have time. Thank you so much for your help.
Also you should import firebase from 'firebase/app', not from 'firebase' 🙂
Definitely :)
With all these tools and compilers and bundlers, it's hard to figure out what does what. And TypeScript definitely has too many compiler options. :smile:
No problem, glad I could help. :slightly_smiling_face:
{ "compilerOptions": { "module": "es6", "esModuleInterop": true, "allowSyntheticDefaultImports": true, }} And a vscode reset fixed my problem.
Before that I couldn't get auth and firestore to load onto firebase. . I could get firebase.auth and firebase.initializeApp with import as firebase from 'firebase/app' but I couldn't get firebase.firestore() no matter what I imported from '@firebase' or 'firebase', which btw is pretty confusing.
Really need some better docs on how to import in different situations, a typescript section in the firebase docs would help a ton of people.
[REQUIRED] Describe your environment
[REQUIRED] Describe the problem
I am trying to create a small module that exports my auth and firestore components. This is a typescript react mobx project. My package.json file looks like this:
and my webpack.config file looks like this:
Steps to reproduce:
With this setup my firebase module looks like this:
This causes warnings in my loader:
And then in the console in chrome:
Its driving me nuts. Ive tried so many combinations to try and fix this and I just can't resolve it. What is going on? I can't seem to get typescript and firestore to play nice together. Please help!
Relevant Code:
Here is the basics of it on stackblitz.
https://stackblitz.com/edit/firebase-issue-sandbox-gtkshz
I assume its got something to do with types not being exported for firestore. I am trying to use this site for our wedding and Im so late with getting things up. Any help as soon as possible would be so helpful! I can provide any missing information otherwise. Thanks so much for anyone giving this their time.