Hammad Ahmed
Hammad Ahmed

Reputation: 885

Firebase: Failed to load function definition from source

I am using firebase functions and I keep receiving this error while trying to deploy or while using emulators.

⬢ functions: Failed to load function definition from source: FirebaseError: Failed to load function definition from source: Failed to generate manifest from function source: SyntaxError: Invalid regular expression: /^[\p{Ll}\p{Lo}][\p{Ll}\p{Lo}\p{N}_-]{0,62}$/: Invalid property name in character class

the error occurs because of this statement, when i comment it the error does not occur.

const functions = require('firebase-functions')

I tried to

  1. reinstall firebase-tools
  2. reinstall node and npm

I am using a 2012 macbook air, any help is appreciated

EDIT

this the only code in the project is in the functions/index.js file, otherwise it is a brand new firebase project initialized by firebase init

const functions = require('firebase-functions')
const cheerio = require('cheerio')


// // wiered error, install older version of firebase-tools and check

// // function
// exports.helloWorld = functions.https.onRequest(async (req,res) => {
//     res.send('hello world') 
// })

// function test(){}

I tried the running index.js directly with node.js and got a more descriptive error message

node index.js /Users/hammad/dev/firebase/prizeBonds/functions/node_modules/firebase-functions/lib/function-builder.js:96 const validKeyPattern = /^[\p{Ll}\p{Lo}][\p{Ll}\p{Lo}\p{N}_-]{0,62}$/u; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Invalid regular expression: /^[\p{Ll}\p{Lo}][\p{Ll}\p{Lo}\p{N}_-]{0,62}$/: Invalid property name in character class at internalCompileFunction (node:internal/vm:73:18) at wrapSafe (node:internal/modules/cjs/loader:1176:20) at Module._compile (node:internal/modules/cjs/loader:1218:27) at Module._extensions..js (node:internal/modules/cjs/loader:1308:10) at Module.load (node:internal/modules/cjs/loader:1117:32) at Module._load (node:internal/modules/cjs/loader:958:12) at Module.require (node:internal/modules/cjs/loader:1141:19) at require (node:internal/modules/cjs/helpers:110:18) at Object. (/Users/hammad/dev/firebase/prizeBonds/functions/node_modules/firebase-functions/lib/index.js:71:14) at Module._compile (node:internal/modules/cjs/loader:1254:14)

Node.js v18.15.0

Upvotes: 0

Views: 2402

Answers (1)

Ajay
Ajay

Reputation: 11

I can't comment due to low points, so leaving an answer for anyone who stumbles here like I did.

I had the same problem with 2015 macbook with the exact same error. After spending a day searching and trying out various different solutions, I finally found it to be a versioning issue due to different node versions installed on the same machine. Here are the steps I took:

  1. Fixed the PATH to ensure that my downloaded node was being run. Earlier, it used to pick the node within the Anaconda package.
  2. Fixed the npm config to update the prefix to use my local .npm-global directory to download firebase.
  3. Downloaded latest versions of modules in package.json

After doing this, the functions finally got deployed.

Upvotes: 1

Related Questions