Home > Net >  FIREBASE FUNCTIONS (Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined)
FIREBASE FUNCTIONS (Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined)

Time:10-30

Trying to explore using firebase functions for a new project at work.

[This is the only good guide I can seem to find despite it being outdated.] https://www.freecodecamp.org/news/how-to-build-a-todo-application-using-reactjs-and-firebase/

However when I get to the login section, after using npm i firebase the command firebase serve stops working and gives the following error.

It only happens after using the install firebase command, removing it doesn't work as it is needed for the auth side of the login. The only difference between the guide and mine is I am building a classroom app but using it to guide me with CRUD for firebase functions, authentication, and firestore.

!  functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
!  Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in D:\CodeyThings\Firebase\Openbrolly-Classroom\functions\node_modules\firebase\package.json
    at throwExportsNotFound (internal/modules/esm/resolve.js:285:9)
    at packageExportsResolve (internal/modules/esm/resolve.js:508:3)
    at resolveExports (internal/modules/cjs/loader.js:450:36)
    at Function.Module._findPath (internal/modules/cjs/loader.js:490:31)
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:888:27)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (D:\CodeyThings\Firebase\Openbrolly-Classroom\functions\APIs\users.js:4:18)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
!  We were unable to load your functions code. (see above)

CodePudding user response:

Just to let you know that the tutorial you are following is using firebase web version 8.x, and you could probably have version 9.x installed, as it was pointed out in this comment. In the same question, a user replied that the firebase sdk you need to use is the Firebase admin-sdk.

If this is not the case and you are using the proper SDK versions, then you might need to show how you are importing your dependencies, here the solution was to change the imports.

Also, in the documentation, we can find a warning to constantly update the firebase-functions sdk, as you mentioned that you get the error when using the install firebase command. The warning is:

In many cases, new features and bug fixes are available only with the latest version of the Firebase CLI and the firebase-functions SDK. It's a good practice to frequently update both the Firebase CLI and the SDK with these commands inside the functions folder of your Firebase project:

npm install firebase-functions@latest firebase-admin@latest --save npm
install -g firebase-tools

These could be the main causes for this error. As you haven't provided any code, I would also check if any other change has been made to some parts of the guide through the updates of firebase, you might have ended up merging code from different versions, as they have done here.

  • Related