Firebase: 无法从源加载函数定义

huangapple go评论84阅读模式
英文:

Firebase: Failed to load function definition from source

问题

我正在使用 Firebase 函数,在尝试部署或使用模拟器时,不断收到以下错误:

> ⬢ functions: 无法从源加载函数定义:FirebaseError:无法从源加载函数定义:无法从函数源生成清单:SyntaxError:无效的正则表达式:/^[\p{Ll}\p{Lo}][\p{Ll}\p{Lo}\p{N}_-]{0,62}$/: 字符类中的无效属性名称

错误发生是因为这个语句,当我注释掉它时错误就不会发生。

const functions = require('firebase-functions')

我尝试过以下方法:

  1. 重新安装 firebase-tools
  2. 重新安装 node 和 npm

我使用的是 2012 年的 MacBook Air,感谢任何帮助。

编辑

项目中唯一的代码位于 functions/index.js 文件中,除此之外,它是一个由 firebase init 初始化的全新 Firebase 项目。

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

我尝试直接使用 node.js 运行 index.js 并得到了一个更详细的错误消息。

>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: 无效的正则表达式:/^[\p{Ll}\p{Lo}][\p{Ll}\p{Lo}\p{N}
-]{0,62}$/: 字符类中的无效属性名称
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.<anonymous> (/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

英文:

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(&#39;firebase-functions&#39;)

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(&#39;firebase-functions&#39;)
const cheerio = require(&#39;cheerio&#39;)


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

// // function
// exports.helloWorld = functions.https.onRequest(async (req,res) =&gt; {
//     res.send(&#39;hello world&#39;) 
// })

// 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.<anonymous> (/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

答案1

得分: 1

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. 修复了PATH以确保运行我下载的node。之前它会选择Anaconda包中的node。
  2. 修复了npm配置,将前缀更新为使用我的本地.npm-global目录来下载firebase。
  3. 下载了package.json中的最新版本模块。

After doing this, the functions finally got deployed.

英文:

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.

huangapple
  • 本文由 发表于 2023年6月1日 06:17:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76377628.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定