4

I'm trying to follow this documentation to use parameterized configuration in my Firebase cloud functions.

The example they give is in Javascript, in particular in how they import defineInt and defineString from firebase-functions/params.

const { defineInt, defineString } = require('firebase-functions/params');

But all my functions code is in Typescript so I tried to translate that into:

import {defineInt} from "firebase-functions/lib/params";

Since apparently firebase-functions/params cannot be resolved.

But then when I try to deploy my functions, I get the following error message:

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

Any idea what's the proper way to import those functions in Typescript?

1
  • 1
    I'm running into the same problem. You're importing correctly from a syntax point of view, but it seems that there is no such module. Package subpath './params' is not defined by "exports" in /Users/.../functions/node_modules/firebase-functions/package.json Commented Oct 28, 2022 at 2:30

2 Answers 2

3

The following import should resolve the issue:

import { https } from "firebase-functions/v1";
import { defineString } from "firebase-functions/params"; // no /lib

const welcomeMessage = defineString("WELCOME_MESSAGE");

export const hello = https.onRequest((request, response) => {
  response.send("Message: " + welcomeMessage);
});

Dependencies:

"firebase-admin": "^11.2.0",
"firebase-functions": "^4.0.1"

And given that the error is an eslint one and it doesn't make sense in that context, adding the following to .eslintrc.js turns the blocking error into a more persmissive warning:

module.exports = {
    ...
    rules: {
        ...
        "import/no-unresolved": "warn",
    },
};
Sign up to request clarification or add additional context in comments.

2 Comments

You should have welcomeMessage.value(), when inside the .onRequest, right?
I had the same issue when targeting the "latest" version. Rolled back to this version fixed the import issue.
3

I was having the same issue with the following firebase functions SDK (node: 16.x.x)

"firebase-admin": "^10.0.2",
"firebase-functions": "^3.18.0"

I changed how I imported the defineSecret and it's now working. I didn't have to change the .eslintrc either

import { defineSecret } from "firebase-functions/v2/params"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.