Firebase Functions本地“文件:"依存关系 [英] Firebase Functions local "file:" dependencies

查看:69
本文介绍了Firebase Functions本地“文件:"依存关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 react-crud-shared 作为 react-crud-backend 的依赖,该依赖项使用了 Firebase Cloud Functions .

react-crud-backend ,我有以下内容:

{
  "name": "react-crud-backend",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    ...
  },
  "dependencies": {
    ...
    "react-crud-shared": "file:../shared",
    ...
  },
  "engines": {
    "node": "8"
  },
  "private": true,
  "devDependencies": {
    ...
  }
}

react-crud-shared ,我有以下内容:

{
  "name": "react-crud-shared",
  "version": "0.0.1",
  "description": "",
  "main": "src/index.js",
  "private": true,
  "dependencies": {
    "lodash": "^4.17.11"
  }
}

它在开发中运行良好:"firebase仅提供功能",但在部署时会引发错误:

Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'react-crud-shared'

是否有一种方法可以使它工作而不必将私有存储库发布到NPM?

谢谢

解决方案

我找到了一个我更喜欢的解决方案.我在这里评论了这个github问题: https://github.com/firebase/firebase-tools/issues/968#issuecomment-460323113 .基本上,我有一个预安装脚本,运行npm pack可以在使用firebase deploy之前复制到功能目录下的程序包.

FWIW我有完全一样的问题.不确定我要如何解决,但是来自文档的此信息很有帮助( https://firebase.google.com/docs/functions/handle-dependencies ):

要为您的函数指定依赖项,请将其添加到package.json文件中.如果通过gcloud命令行工具进行部署,则还可以预安装依赖项,并将其与功能一起部署.默认情况下,将node_modules文件夹添加到您的.gcloudignore文件中,并且不会作为部署的一部分上载.要部署预安装的依赖项,请在部署功能之前从.gcloudignore文件中删除node_modules/.

注意:部署预安装的依赖项仅适用于gcloud. Firebase CLI会忽略本地的node_modules文件夹.

因此,看来您可以先运行"npm install"在本地,然后使用gcloud进行部署,因为它将复制您的node_modules目录,该目录中将有您的对等依赖项.

但是,确实有点恶臭,我必须从Firebase CLI切换到gcloud进行部署. gh.

I'm using a react-crud-shared as dependency for react-crud-backend which uses Firebase Cloud Functions.

At react-crud-backend I have the following:

{
  "name": "react-crud-backend",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    ...
  },
  "dependencies": {
    ...
    "react-crud-shared": "file:../shared",
    ...
  },
  "engines": {
    "node": "8"
  },
  "private": true,
  "devDependencies": {
    ...
  }
}

At react-crud-shared I have the following:

{
  "name": "react-crud-shared",
  "version": "0.0.1",
  "description": "",
  "main": "src/index.js",
  "private": true,
  "dependencies": {
    "lodash": "^4.17.11"
  }
}

It works fine on development: "firebase serve --only functions", but an error is thrown on deployment:

Did you list all required modules in the package.json dependencies?
Detailed stack trace: Error: Cannot find module 'react-crud-shared'

Is there a way to make it work without having to publish the private repository to NPM?

Thanks

解决方案

EDIT: I found a solution for this that I like much better. I commented on this github issue here: https://github.com/firebase/firebase-tools/issues/968#issuecomment-460323113 . Basically, I have a preinstall script the runs npm pack to copy over the package under the functions directory before I use firebase deploy.

FWIW I have the exact same problem. Not exactly sure how I'm going to solve it, but this information from the doc was helpful (https://firebase.google.com/docs/functions/handle-dependencies):

To specify a dependency for your function, add it to your package.json file. If you are deploying through the gcloud command-line tool, you can also pre-install dependencies and deploy them alongside your function. By default, the node_modules folder is added to your .gcloudignore file and is not uploaded as part of your deployment. To deploy pre-installed dependencies, remove node_modules/ from the .gcloudignore file before deploying your function.

Note: Deploying pre-installed dependencies works with gcloud only; the Firebase CLI ignores the local node_modules folder.

Thus, it appears you could first run "npm install" locally, and then use gcloud for deployment, as it would copy up your node_modules directory, which would have your peer dependency in it.

Really kind of stinks, though, that I would have to switch to gcloud from firebase CLI for deployment. Ugh.

这篇关于Firebase Functions本地“文件:"依存关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆