Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module not found: Default condition should be last one #7005

Closed
jfbaraky opened this issue Feb 2, 2023 · 42 comments · Fixed by #7007
Closed

Module not found: Default condition should be last one #7005

jfbaraky opened this issue Feb 2, 2023 · 42 comments · Fixed by #7007
Labels

Comments

@jfbaraky
Copy link

jfbaraky commented Feb 2, 2023

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:

  1. yarn add firebase
  2. 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';
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@jfbaraky
Copy link
Author

jfbaraky commented Feb 2, 2023

Looks like the Next.JS is emitting this error when importing the Firebase.
https://nextjs.org/docs/messages/module-not-found

@aaronmgdr
Copy link

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

@joshdchang
Copy link

This seems to be a result of #6981. I submitted a PR to fix this: #7006. See: #7002 (comment)

@toan-superman
Copy link

I got the same issue here, and it just happened this morning. How can I fix that ?
image

@D3OXY
Copy link

D3OXY commented Feb 3, 2023

Same issue
Firebase SDK version: 9.17.0
image

@Angryman18
Copy link

here is the solution. change the version run yarn install

Screenshot from 2023-02-03 13-24-19

@Angryman18
Copy link

from fixed to the version. remove ^ also

@VuHuyDot
Copy link

VuHuyDot commented Feb 3, 2023

After following @Angryman18 suggestion. It has been fixed. Thank you very much

@bradley-owens
Copy link

how do i change the firebase version angry man

@fvilers
Copy link

fvilers commented Feb 3, 2023

We can revert to version 9.16.0 to avoid the issue

@Angryman18
Copy link

how do i change the firebase version angry man

In package.json file

@bradley-owens
Copy link

this did not fix my issue

@rizafran rizafran added v9 and removed needs-triage labels Feb 3, 2023
@gowthamtirri
Copy link

this did not fix my issue

  1. npm un firebase
  2. npm i firebase@9.16.0

Solved my issue "Module not found: Default condition should be last one "

@Naman-Sogani
Copy link

  1. npm un firebase
  2. npm i firebase@9.16.0

Solved my issue "Module not found: Default condition should be last one "

Its working for me bro thnx..

@Reeywhaar
Copy link

Reeywhaar commented Feb 3, 2023

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

@AnthonyNahas
Copy link

AnthonyNahas commented Feb 3, 2023

I am facing the same issue after upgrading the lib from v9.16.0 to v9.17.0

Bildschirm­foto 2023-02-03 um 12 03 01

@iamSuraZz
Copy link

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)

@jfbaraky
Copy link
Author

jfbaraky commented Feb 3, 2023

@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';

@jfbaraky
Copy link
Author

jfbaraky commented Feb 3, 2023

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).

@iamSuraZz
Copy link

Fixed the error was here :
import firebase from "firebase/compat/app";
import "firebase/compat/auth";
import "firebase/compat/firestore";
import "firebase/compat/database";

@BossBele
Copy link

BossBele commented Feb 3, 2023

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.

@miramgh
Copy link

miramgh commented Feb 3, 2023

Im having the same issue
none of those solutions worked for me

@PaulvdDool
Copy link

Version 9.16.0 strict (without ^) worked for me.

@lincolnthree
Copy link

This just started for me when upgrading "^9.16.0", to `"^9.17.0". Was working fine before.

@jbalidiong
Copy link
Contributor

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.

@Angryman18
Copy link

^ 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 jbalidiong added the bug label Feb 3, 2023
@Reeywhaar
Copy link

@jbalidiong issue caused by this commit 0bab0b7

@SANDAY-JS
Copy link

Changed the version from latest to 9.15.0, and it worked for me.
Also, make sure to remove ^.

@eugenevk
Copy link

eugenevk commented Feb 3, 2023

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.

@hsubox76
Copy link
Contributor

hsubox76 commented Feb 3, 2023

I have the fix merged and am working on an emergency release ASAP, will update when it is out.

@dariovargaos
Copy link

@Angryman18 guys just follow steps from this guy. It solved the issue.

@ginagr
Copy link

ginagr commented Feb 3, 2023

Angryman steps work for me after switching from yarn to npm if that helps anyone else (you may need to do npm install --force)

@hsubox76
Copy link
Contributor

hsubox76 commented Feb 3, 2023

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.

@fvadouko
Copy link

fvadouko commented Feb 3, 2023

It works for firbase 9.16.0 because we have this issue with vercel.

@danielalejandroalanis
Copy link

Solved with the new version (9.17.1), I had to delete package-lock and node_modules for a clean install.

@BecayeSoft
Copy link

this did not fix my issue

  1. npm un firebase
  2. 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...

@BecayeSoft
Copy link

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.

@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?

@eduhsoto
Copy link

eduhsoto commented Feb 4, 2023

this did not fix my issue

  1. npm un firebase
  2. 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?

@Mydulislam
Copy link

npm un firebase
npm i firebase@9.16.0
Solved my issue "Module not found: Default condition should be last one "

@singhrishabh93
Copy link

here is the solution. change the version run yarn install

Screenshot from 2023-02-03 13-24-19

Thank You so much

@eugenevk
Copy link

eugenevk commented Feb 13, 2023

Deleting node_modules and then reinstalling everything with npm (with firebase version set to 9.17.1) fixed it for me.

@firebase firebase locked and limited conversation to collaborators Mar 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.