Firebase-tools: 函数仅部署错误,引用父应用程序 node_modules 文件夹

创建于 2018-04-19  ·  21评论  ·  资料来源: firebase/firebase-tools

版本信息

火力基地:3.18.4
节点:8.10.0
npm:5.6.0

平台信息

视窗

重现步骤

firebase deploy --only functions

预期行为

Firebase 云功能将成功部署。

实际行为

收到错误,因为云函数构建似乎是从应用程序的根级别引用 node_modules 文件夹。 @types/d3@types/googlemaps包含在我的应用程序 package.json 文件中,而不是我的函数 package.json 文件中。

```PS [本地机器上的路径]> firebase deploy --only 功能

=== 正在部署到“PROJECT_NAME”...

我部署功能
运行命令:npm --prefix "$RESOURCE_DIR" run lint

函数@ lint [本地机器上的路径]\函数
tslint --project tsconfig.json

运行命令: npm --prefix "$RESOURCE_DIR" 运行构建

函数@构建 [本地机器上的路径]\函数
tsc

../node_modules/@types/d3-axis/index.d.ts(50,36):错误 TS2304:找不到名称“SVGSVGElement”。
../node_modules/@types/d3-axis/index.d.ts(50,52):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(32,23):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(39,27):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(50,27):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(63,27):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(63,77):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(70,27):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(81,32):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(94,32):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(94,72):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(98,23):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(121,28):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(126,23):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(138,30):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(164,36):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(191,45):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-brush/index.d.ts(223,38):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-chord/index.d.ts(360,16):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-chord/index.d.ts(368,22):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-dispatch/index.d.ts(8,37):错误 TS2304:找不到名称“EventTarget”。
../node_modules/@types/d3-dispatch/index.d.ts(18,36):错误 TS2304:找不到名称“EventTarget”。
../node_modules/@types/d3-drag/index.d.ts(19,38):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-drag/index.d.ts(24,36):错误 TS2304:找不到名称“HTMLElement”。
../node_modules/@types/d3-drag/index.d.ts(24,50):错误 TS2304:找不到名称“SVGSVGElement”。
../node_modules/@types/d3-drag/index.d.ts(24,66):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-drag/index.d.ts(390,37):错误 TS2304:找不到名称“窗口”。
../node_modules/@types/d3-drag/index.d.ts(402,36):错误 TS2304:找不到名称“窗口”。
../node_modules/@types/d3-fetch/index.d.ts(18,42):错误 TS2304:找不到名称“RequestInit”。
../node_modules/@types/d3-fetch/index.d.ts(18,64):错误 TS2304:找不到名称“Blob”。
../node_modules/@types/d3-fetch/index.d.ts(27,44):错误 TS2304:找不到名称“RequestInit”。
../node_modules/@types/d3-fetch/index.d.ts(41,12):错误 TS2304:找不到名称“RequestInit”。
../node_modules/@types/d3-fetch/index.d.ts(82,11):错误 TS2304:找不到名称“RequestInit”。
../node_modules/@types/d3-fetch/index.d.ts(100,12):错误 TS2304:找不到名称“RequestInit”。
../node_modules/@types/d3-fetch/index.d.ts(145,11):错误 TS2304:找不到名称“RequestInit”。
../node_modules/@types/d3-fetch/index.d.ts(157,42):错误 TS2304:找不到名称“RequestInit”。
../node_modules/@types/d3-fetch/index.d.ts(157,64):错误 TS2304:找不到名称“文档”。
../node_modules/@types/d3-fetch/index.d.ts(167,74):错误 TS2304:找不到名称“HTMLImageElement”。
../node_modules/@types/d3-fetch/index.d.ts(179,72):错误 TS2304:找不到名称“RequestInit”。
../node_modules/@types/d3-fetch/index.d.ts(189,41):错误 TS2304:找不到名称“RequestInit”。
../node_modules/@types/d3-fetch/index.d.ts(189,63):错误 TS2304:找不到名称“文档”。
../node_modules/@types/d3-fetch/index.d.ts(199,42):错误 TS2304:找不到名称“RequestInit”。
../node_modules/@types/d3-fetch/index.d.ts(212,12):错误 TS2304:找不到名称“RequestInit”。
../node_modules/@types/d3-fetch/index.d.ts(254,11):错误 TS2304:找不到名称“RequestInit”。
../node_modules/@types/d3-fetch/index.d.ts(266,41):错误 TS2304:找不到名称“RequestInit”。
../node_modules/@types/d3-fetch/index.d.ts(266,63):错误 TS2304:找不到名称“XMLDocument”。
../node_modules/@types/d3-selection/index.d.ts(17,24):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-selection/index.d.ts(17,49):错误 TS2304:找不到名称“文档”。
../node_modules/@types/d3-selection/index.d.ts(17,60):错误 TS2304:找不到名称“窗口”。
../node_modules/@types/d3-selection/index.d.ts(34,20):错误 TS2304:找不到名称“文档”。
../node_modules/@types/d3-selection/index.d.ts(36,27):错误 TS2304:找不到名称“节点”。
../node_modules/@types/d3-selection/index.d.ts(36,34):错误 TS2304:找不到名称“节点”。
../node_modules/@types/d3-selection/index.d.ts(37,28):错误 TS2304:找不到名称“节点”。
../node_modules/@types/d3-selection/index.d.ts(37,44):错误 TS2304:找不到名称“节点”。
../node_modules/@types/d3-selection/index.d.ts(37,51):错误 TS2304:找不到名称“节点”。
../node_modules/@types/d3-selection/index.d.ts(38,39):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-selection/index.d.ts(39,42):错误 TS2304:找不到名称“NodeListOf”。
../node_modules/@types/d3-selection/index.d.ts(39,53):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-selection/index.d.ts(45,32):错误 TS2304:找不到名称“HTMLElement”。
../node_modules/@types/d3-selection/index.d.ts(45,46):错误 TS2304:找不到名称“SVGSVGElement”。
../node_modules/@types/d3-selection/index.d.ts(45,62):错误 TS2304:找不到名称“SVGGElement”。
../node_modules/@types/d3-selection/index.d.ts(110,110):错误 TS2304:找不到名称“HTMLElement”。
../node_modules/@types/d3-selection/index.d.ts(142,113):错误 TS2304:找不到名称“HTMLElement”。
../node_modules/@types/d3-selection/index.d.ts(873,43):错误 TS2304:找不到名称“HTMLElement”。
../node_modules/@types/d3-selection/index.d.ts(977,61):错误 TS2304:找不到名称“TouchList”。
../node_modules/@types/d3-selection/index.d.ts(989,64):错误 TS2304:找不到名称“TouchList”。
../node_modules/@types/d3-selection/index.d.ts(1013,29):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-selection/index.d.ts(1025,15):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-selection/index.d.ts(1033,18):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-selection/index.d.ts(1040,15):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-selection/index.d.ts(1040,35):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-selection/index.d.ts(1108,33):错误 TS2304:找不到名称“窗口”。
../node_modules/@types/d3-selection/index.d.ts(1108,42):错误 TS2304:找不到名称“文档”。
../node_modules/@types/d3-selection/index.d.ts(1108,53):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-selection/index.d.ts(1108,63):错误 TS2304:找不到名称“窗口”。
../node_modules/@types/d3-selection/index.d.ts(1122,44):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-selection/index.d.ts(1133,45):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-selection/index.d.ts(1154,46):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-selection/index.d.ts(1163,49):错误 TS2304:找不到名称“元素”。
../node_modules/@types/d3-selection/index.d.ts(1163,97):错误 TS2304:找不到名称“NodeListOf”。
../node_modules/@types/d3-shape/index.d.ts(304,16):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(312,22):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(757,16):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(765,22):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(935,16):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(943,22):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(1230,16):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(1238,22):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(1536,16):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(1544,22):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(1650,15):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(1686,15):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(2016,16):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(2024,22):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(2196,16):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(2204,22):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(2273,19):错误 TS2304:找不到名称“CanvasPathMethods”。
../node_modules/@types/d3-shape/index.d.ts(2358,16):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-shape/index.d.ts(2366,22):错误 TS2304:找不到名称“CanvasRenderingContext2D”。
../node_modules/@types/d3-transition/index.d.ts(572,65):错误 TS2304:找不到名称“HTMLElement”。
../node_modules/@types/d3-transition/index.d.ts(583,104):错误 TS2304:找不到名称“HTMLElement”。
../node_modules/@types/d3-zoom/index.d.ts(20,37):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(33,29):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(37,19):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(54,28):错误 TS2304:找不到名称“节点”。
../node_modules/@types/googlemaps/index.d.ts(788,30):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(799,36):错误 TS2304:找不到名称“节点”。
../node_modules/@types/googlemaps/index.d.ts(812,26):错误 TS2304:找不到名称“节点”。
../node_modules/@types/googlemaps/index.d.ts(1136,20):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1137,22):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1138,18):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1139,22):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1140,23):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1141,23):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1142,29):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1143,24):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1220,21):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1225,25):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1236,17):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1653,32):错误 TS2304:找不到名称“节点”。
../node_modules/@types/googlemaps/index.d.ts(1668,64):错误 TS2304:找不到名称“文档”。
../node_modules/@types/googlemaps/index.d.ts(1668,75):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1669,27):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1692,64):错误 TS2304:找不到名称“文档”。
../node_modules/@types/googlemaps/index.d.ts(1692,75):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1693,27):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1709,64):错误 TS2304:找不到名称“文档”。
../node_modules/@types/googlemaps/index.d.ts(1709,75):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1710,27):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1941,32):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(1942,28):错误 TS2304:找不到名称“节点”。
../node_modules/@types/googlemaps/index.d.ts(2394,36):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(2398,29):错误 TS2304:找不到名称“元素”。
../node_modules/@types/googlemaps/index.d.ts(2455,37):错误 TS2304:找不到名称“HTMLInputElement”。
../node_modules/@types/googlemaps/index.d.ts(2616,40):错误 TS2304:找不到名称“HTMLDivElement”。
../node_modules/@types/googlemaps/index.d.ts(2663,37):错误 TS2304:找不到名称“HTMLInputElement”。
npm 错误! 代码生命周期
npm 错误! 错误号 2
npm 错误! 函数@构建: tsc
npm 错误! 退出状态 2
npm 错误!
npm 错误! 在 functions@ build 脚本中失败。
npm 错误! 这可能不是 npm 的问题。 上面可能有额外的日志输出。

npm 错误! 可以在以下位置找到此运行的完整日志:
npm 错误! [本地机器上的路径]\AppData\Roaming\npm-cache_logs\2018-04-19T16_10_21_812Z-debug.log

错误:函数预部署错误:命令以非零退出代码终止2```

最有用的评论

@laurenzlong再次感谢! 这帮助我找到了解决问题所需要做的事情。

为了别人运行到这个问题-我能够通过修改功能构建脚本使用获得成功构建功能tsc --skipLibCheck ,而不是tsc从内部functions/package.json 。 这告诉打字稿编译器跳过所有声明文件的类型检查。

所有21条评论

如果您在函数文件夹中运行npm run build ,它会成功吗?

如果你在你的函数文件夹中运行 npm run build ,它会成功吗?

它不是。 同样的错误。

然后这与您的 TypeScript 设置或您如何在代码中导入模块有关。 这不是 firebase-tools 的错误。

@laurenzlong好的,感谢您花时间帮助我解决这个问题。 我想我想知道为什么 firebase 云功能甚至关心我在我的应用程序中包含哪些包。 我创建了一个关于我收到的错误的简化演示。 云函数构建良好,直到我包含一些类型定义,例如@types/googlemaps 。 我认为无论我在本演示的根级别中包含任何类型定义包,都应该构建云函数。

“npm run build”使用常规的“tsc”来构建你的文件。 这与 Firebase 或 Cloud Functions 无关。

@laurenzlong再次感谢! 这帮助我找到了解决问题所需要做的事情。

为了别人运行到这个问题-我能够通过修改功能构建脚本使用获得成功构建功能tsc --skipLibCheck ,而不是tsc从内部functions/package.json 。 这告诉打字稿编译器跳过所有声明文件的类型检查。

@dylanjmcdonald或将其放入 tsconfig.json 文件中:

    // "isolatedModules": true,               /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */

    "skipLibCheck": true,
    /* Strict Type-Checking Options */
    "strict": true,

谢谢你的提醒,顺便说一句👍

但是,如果您不想跳过检查声明怎么办? 在我的一个云功能中,我使用了 es2017 的 Objects.entries()。 我在 tsconfig.json 中设置了它,但是因为它正在跳过它,所以在执行函数时会引发错误。 有没有其他办法解决这个问题?

我通过添加解决了同样的问题:
“类型根”:[
“./functions/node_modules/@types”
]
到函数文件夹中的 tsconfig.json

当为我初始化函数时,库存自动生成的打字稿会发生这种情况。

只是自动生成的代码和导入与示例中的完全相同。

这似乎是因为 tsc 会在您的进程树中查找类型并尝试对@types文件中的所有内容进行类型糟糕了

我认为最正确的解决方案是按照贡格万根的建议去做。 将“node_modules/@types”添加到 typeRoots 以便模块解析算法不会在树上发疯。

感谢@dylanjmcdonald,我得到了同样的问题,我已经通过使用 tsc --skipLibCheck 解决了它

@dylanjmcdonald tsc --skipLibCheck in ./functions/package.json为我工作,谢谢!

我通过在./functions/tsconfig.json中将"dom"compilerOptions.lib来修复。

{
  "compilerOptions": {
    "lib": ["es6", "dom"],
    "module": "commonjs",
    "noImplicitReturns": true,
    "outDir": "lib",
    "sourceMap": true,
    "target": "es6"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

这也应该有效。 我使用了@yamitzky解决方案并进行了功能部署。 根据我查看的谷歌开发人员代码,以下内容可用。
{ "compilerOptions": { "lib": ["es6"], "module": "commonjs", "noImplicitReturns": true, "outDir": "lib", "sourceMap": true, "target": "es6", "skipLibCheck": true, "typeRoots": ["./functions/node_modules/@types"] }, "compileOnSave": true, "include": [ "src" ] }

有解决方法很好,但是这些解决方案之一应该真的在firebase init生成的.tsconfig firebase init 。 有谁知道我们如何才能重新打开这个问题?

您可以重新打开此问题,但我可以告诉您,我们可能不会将dom到模板tsconfig.jsonlib属性中。 这是让开发人员起步的最低要求,并且默认不需要dom 。 如果你有强烈的反感,请随时在这个 repo 上打开一个 pull request 更改模板,但我不认为这是我们会做出的改变。

谢谢先生

确保您的 .ts 文件与 lib 中的 .js 同名,并将其包含在 package.json 中

只是为了澄清@gongevangen的解决方案有效,但请确保将"typeRoots"键放在"compilerOptions"

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "typeRoots": [
      "./functions/node_modules/@types"
    ],
  },
  "compileOnSave": true,
  "include": [
    "src"
  ],
}

有点困惑为什么这不会包含在样板文件中......甚至在任何 Firebase tuts 的任何地方都没有提到。

我同意@evanb2 - 这只花了我一个小时! 当然,至少值得在这里提一下: https :

上帝保佑你Evanb2! :)

此页面是否有帮助?
0 / 5 - 0 等级