narduk
narduk

Reputation: 1134

ERR_PACKAGE_PATH_NOT_EXPORTED with firebase-admin 11.0.0 and firebase-functions 3.21.2

I'm trying to update to the most recent versions of firebase-admin (11.0.0) and firebase-functions (3.21.2). I'm using firebase-tools 11.1.0. I get this error when try to deploy my functions:

Error: Failed to load function definition from source: Failed to generate manifest from function source: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib' is not defined by "exports" in /Users/myuser/Documents/myproject/node_modules/firebase-functions/package.json

I've seen similar errors in StackOverflow like this one or this one but this error is slightly different. The problem is not in firebase or firebase-admin dependencies but with firebase-functions.

Using firebase-functions 3.14.1 works (I get some warnings though) but I'd like to update to the latest version so I can hopefully get rid of warnings and get the latest updates.

How can I fix this?

Thanks!

Upvotes: 7

Views: 2941

Answers (3)

Rohit Goyal
Rohit Goyal

Reputation: 89

The issue is related to how you are importing in your application. I was putting extra slash at the end which is giving me the same error.

From

const admin   = require('firebase-admin/');

To

const admin   = require('firebase-admin');

Upvotes: 0

Andrés
Andrés

Reputation: 515

In the documentation, we can find a warning to constantly update the firebase-functions sdk. 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 message. As you haven't provided any code.

Additonally, it might be conflicting with the firebase-admin 11.0 version. This GitHub issue claims firebase-admin 11.0 does not support firebase-functions version 3.21.2. But it succeeds with firebase-admin 10.0 and firebase-functions version 3.21.2.

I’d suggest using firebase-admin 10.0 and firebase-functions version 3.21.2.

Upvotes: 2

narduk
narduk

Reputation: 1134

As the error described, the problem was that I had imports referencing the lib folder of firebase-functions like this:

import { HttpsError } from 'firebase-functions/lib/providers/https'
...
throw new HttpsError('failed-precondition', 'An error')

The problem was gone after removing all of them and replacing with something like the following:

import { https } from 'firebase-functions'
...
throw new https.HttpsError('failed-precondition', 'An error')

The first approach worked until 3.14.1. Above that, it looks like we can't reference the lib folder in the from. Not ideal because I wanted to avoid the namespace when using these types, but at least it works.

Upvotes: 10

Related Questions