Module not found: Default condition should be last one
jfbaraky opened this issue Β· 42 comments
Describe your environment
- Operating System version: macOS Monterey 12.4
- Browser version: Google Chrome 109.0.5414.119
- Firebase SDK version: 9.17.0
- Firebase Product: any
Describe the problem
When installing the version 9.17.0
, I was getting this error on the import:
Module not found: Default condition should be last one
> 1 | import { initializeApp, getApps, getApp } from 'firebase/app';
2 | import { getAnalytics, isSupported } from 'firebase/analytics';
3 | import { getAuth } from 'firebase/auth';
Doesn't matter the order of the imports.
Rolling back to the 9.16.0 solved the problem.
Steps to reproduce:
yarn add firebase
- import any firebase lib
Relevant Code:
The error is happening on the import first firebase package, doesn't matter which one of them.
import { initializeApp, getApps, getApp } from 'firebase/app';
import { getAnalytics, isSupported } from 'firebase/analytics';
import { getAuth } from 'firebase/auth';
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Looks like the Next.JS is emitting this error when importing the Firebase.
https://nextjs.org/docs/messages/module-not-found
also getting this. It only started about a hour ago and I even tried re building an old deploy commit. only difference it seems is firebase 9.17 just dropped
This seems to be a result of #6981. I submitted a PR to fix this: #7006. See: #7002 (comment)
from fixed to the version. remove ^
also
After following @Angryman18 suggestion. It has been fixed. Thank you very much
how do i change the firebase version angry man
We can revert to version 9.16.0 to avoid the issue
how do i change the firebase version angry man
In package.json file
this did not fix my issue
this did not fix my issue
- npm un firebase
- npm i firebase@9.16.0
Solved my issue "Module not found: Default condition should be last one "
- npm un firebase
- npm i firebase@9.16.0
Solved my issue "Module not found: Default condition should be last one "
Its working for me bro thnx..
Checked all package.json files with following script
/**
* Checks if all package.json has
* "default" export in `exports` entry
* to be the last one
*/
const exec = require('child_process').execSync
function main() {
const packages = exec('find node_modules -type f -name package.json').toString().split('\n')
for (const pkg of packages) {
try {
const data = require(`./${pkg}`)
if (!data.exports) {
continue
}
if (!checkIfDefaultIsLast(data.exports)) {
// console.info(pkg, data.exports, checkIfDefaultIsLast(data.exports))
console.warn('FAIL', pkg)
} else {
// console.info('OK ', pkg)
}
} catch (e) {
if (e instanceof Error) {
if (e.message.endsWith('Unexpected end of JSON input')) continue
}
console.error(e.message)
}
}
}
function checkIfDefaultIsLast(item) {
if (typeof item === 'string') return true
const entries = Array.from(Object.entries(item))
const keys = entries.map(([key]) => key)
if (keys.includes('default') && keys.indexOf('default') !== keys.length - 1) {
return false
}
for (const [, value] of Object.entries(item)) {
if (!checkIfDefaultIsLast(value)) return false
}
return true
}
main()
And it seems only firebase packages have exports entry messed up
Reverted to 9.16.0
Downgraded to 9.16.0 but now throwing new error :
Compiled with problems:X
ERROR in ./src/FireBase/Firebase.js 14:15-37
export 'default' (imported as 'firebase') was not found in 'firebase/app' (possible exports: FirebaseError, SDK_VERSION, _DEFAULT_ENTRY_NAME, _addComponent, _addOrOverwriteComponent, _apps, _clearComponents, _components, _getProvider, _registerComponent, _removeServiceInstance, deleteApp, getApp, getApps, initializeApp, onLog, registerVersion, setLogLevel)
@iamSuraZz your issue probably is related to your import.
You need to do a named import instead of a default one:
import { initializeApp, getApps, getApp } from 'firebase/app';
instead of
import firebase from 'firebase/app';
If you're having trouble to move to the 9.16.0
, check if you have a ^
on the firebase version inside the package.json
file. This will allow the install to check for new minor version, and will install the 9.17.0
.
"firebase": "9.16.0"
instead of "firebase": "^9.16.0"
You can also create a .npmrc
file on the root of your project with save-exact=true
inside to force any new added package to be exact (you still need to remove the already existing ^
).
After the removal, you will need to run another npm i
(or yarn
).
Fixed the error was here :
import firebase from "firebase/compat/app";
import "firebase/compat/auth";
import "firebase/compat/firestore";
import "firebase/compat/database";
Changing firebase version from "^9.9.0" to "9.9.0" worked for me.
In some cases, removing the "^" from the firebase version in package.json, suprisingly works.
Im having the same issue
none of those solutions worked for me
Version 9.16.0 strict (without ^) worked for me.
This just started for me when upgrading "^9.16.0",
to `"^9.17.0". Was working fine before.
Hi everyone, thanks for bringing this issue to our attention. I was able to reproduce the behavior. Let me check what we can do for this issue or bring someone here that can provide more context about it. Iβll update this thread if I have any information to share.
^ means you will have minimum that version but with all upcoming patch releases & upgrades and removing ^ meaning you sticky want to install that particular version without any patch releases and updates on that version
@jbalidiong issue caused by this commit 0bab0b7
Changed the version from latest to 9.15.0
, and it worked for me.
Also, make sure to remove ^
.
In combination with Quasar CLI 2.0.0 it's even worse. After upgrade Quasar CLI from 1.4.0 to 2.0.0, axios from 0.26.1 to 1.3.1 and then upgrading firebase from 9.6.6 to 9.17.0, got same error, then downgraded to 9.6.6 and it didn't even work any more. Had to undo all package upgrades and redo Quasar etc.
I have the fix merged and am working on an emergency release ASAP, will update when it is out.
@Angryman18 guys just follow steps from this guy. It solved the issue.
Angryman steps work for me after switching from yarn to npm if that helps anyone else (you may need to do npm install --force)
Version 9.17.1 has just been published to NPM, please let me know if anyone's still having problems.
If you still have issues with 9.17.1, before reporting the issue here, make sure to delete your node_modules
and package-lock.json
/yarn.lock
files and reinstall. If yarn or npm doesn't overwrite the old node_modules/@firebase/**/package.json
files, which sometimes happens when you do an upgrade/downgrade without deleting everything, you'll continue to have the same problem.
It works for firbase 9.16.0 because we have this issue with vercel.
Solved with the new version (9.17.1), I had to delete package-lock and node_modules for a clean install.
this did not fix my issue
- npm un firebase
- npm i firebase@9.16.0
Solved my issue "Module not found: Default condition should be last one "
Thanks, man! It worked like a charm...
Version 9.17.1 has just been published to NPM, please let me know if anyone's still having problems.
If you still have issues with 9.17.1, before reporting the issue here, make sure to delete your
node_modules
andpackage-lock.json
/yarn.lock
files and reinstall. If yarn or npm doesn't overwrite the oldnode_modules/@firebase/**/package.json
files, which sometimes happens when you do an upgrade/downgrade without deleting everything, you'll continue to have the same problem.
@hsubox76, I created a new project with firebase 9.17.1. But now I'm getting some errors like this one:
Error: node_modules/@angular/fire/compat/firestore/interfaces.d.ts:13:18 - error TS2430: Interface 'DocumentSnapshotExists' incorrectly extends interface 'DocumentSnapshot'.
The types returned by 'data(...)' are incompatible between these types.
Type 'T' is not assignable to type 'DocumentData | undefined'.
Type 'T' is not assignable to type 'DocumentData'.
Do you have any idea?
this did not fix my issue
- npm un firebase
- npm i firebase@9.16.0
Solved my issue "Module not found: Default condition should be last one "
Thanks, man! It worked like a charm...
this solution worked for me ... it is bug only version 17?
npm un firebase
npm i firebase@9.16.0
Solved my issue "Module not found: Default condition should be last one "
Deleting node_modules and then reinstalling everything with npm (with firebase version set to 9.17.1) fixed it for me.