Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions only deploy erroring, referencing parent application node_modules folder #749

Closed
dylanjmcdonald opened this issue Apr 19, 2018 · 21 comments

Comments

@dylanjmcdonald
Copy link

@dylanjmcdonald dylanjmcdonald commented Apr 19, 2018

Version info

firebase: 3.18.4
node: 8.10.0
npm: 5.6.0

Platform Information

Windows

Steps to reproduce

firebase deploy --only functions

Expected behavior

Firebase cloud functions will deploy successfully.

Actual behavior

Receiving an error because the cloud functions build seems to be referencing the node_modules folder from the root level of the application. @types/d3 and @types/googlemaps are included in my applications package.json file and not my functions package.json file.

=== Deploying to 'PROJECT_NAME'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint [PATH ON LOCAL MACHINE]\functions
> tslint --project tsconfig.json

Running command: npm --prefix "$RESOURCE_DIR" run build

> functions@ build [PATH ON LOCAL MACHINE]\functions
> tsc

../node_modules/@types/d3-axis/index.d.ts(50,36): error TS2304: Cannot find name 'SVGSVGElement'.
../node_modules/@types/d3-axis/index.d.ts(50,52): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(32,23): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(39,27): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(50,27): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(63,27): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(63,77): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(70,27): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(81,32): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(94,32): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(94,72): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(98,23): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(121,28): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(126,23): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(138,30): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(164,36): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(191,45): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-brush/index.d.ts(223,38): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-chord/index.d.ts(360,16): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-chord/index.d.ts(368,22): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-dispatch/index.d.ts(8,37): error TS2304: Cannot find name 'EventTarget'.
../node_modules/@types/d3-dispatch/index.d.ts(18,36): error TS2304: Cannot find name 'EventTarget'.
../node_modules/@types/d3-drag/index.d.ts(19,38): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-drag/index.d.ts(24,36): error TS2304: Cannot find name 'HTMLElement'.
../node_modules/@types/d3-drag/index.d.ts(24,50): error TS2304: Cannot find name 'SVGSVGElement'.
../node_modules/@types/d3-drag/index.d.ts(24,66): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-drag/index.d.ts(390,37): error TS2304: Cannot find name 'Window'.
../node_modules/@types/d3-drag/index.d.ts(402,36): error TS2304: Cannot find name 'Window'.
../node_modules/@types/d3-fetch/index.d.ts(18,42): error TS2304: Cannot find name 'RequestInit'.
../node_modules/@types/d3-fetch/index.d.ts(18,64): error TS2304: Cannot find name 'Blob'.
../node_modules/@types/d3-fetch/index.d.ts(27,44): error TS2304: Cannot find name 'RequestInit'.
../node_modules/@types/d3-fetch/index.d.ts(41,12): error TS2304: Cannot find name 'RequestInit'.
../node_modules/@types/d3-fetch/index.d.ts(82,11): error TS2304: Cannot find name 'RequestInit'.
../node_modules/@types/d3-fetch/index.d.ts(100,12): error TS2304: Cannot find name 'RequestInit'.
../node_modules/@types/d3-fetch/index.d.ts(145,11): error TS2304: Cannot find name 'RequestInit'.
../node_modules/@types/d3-fetch/index.d.ts(157,42): error TS2304: Cannot find name 'RequestInit'.
../node_modules/@types/d3-fetch/index.d.ts(157,64): error TS2304: Cannot find name 'Document'.
../node_modules/@types/d3-fetch/index.d.ts(167,74): error TS2304: Cannot find name 'HTMLImageElement'.
../node_modules/@types/d3-fetch/index.d.ts(179,72): error TS2304: Cannot find name 'RequestInit'.
../node_modules/@types/d3-fetch/index.d.ts(189,41): error TS2304: Cannot find name 'RequestInit'.
../node_modules/@types/d3-fetch/index.d.ts(189,63): error TS2304: Cannot find name 'Document'.
../node_modules/@types/d3-fetch/index.d.ts(199,42): error TS2304: Cannot find name 'RequestInit'.
../node_modules/@types/d3-fetch/index.d.ts(212,12): error TS2304: Cannot find name 'RequestInit'.
../node_modules/@types/d3-fetch/index.d.ts(254,11): error TS2304: Cannot find name 'RequestInit'.
../node_modules/@types/d3-fetch/index.d.ts(266,41): error TS2304: Cannot find name 'RequestInit'.
../node_modules/@types/d3-fetch/index.d.ts(266,63): error TS2304: Cannot find name 'XMLDocument'.
../node_modules/@types/d3-selection/index.d.ts(17,24): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-selection/index.d.ts(17,49): error TS2304: Cannot find name 'Document'.
../node_modules/@types/d3-selection/index.d.ts(17,60): error TS2304: Cannot find name 'Window'.
../node_modules/@types/d3-selection/index.d.ts(34,20): error TS2304: Cannot find name 'Document'.
../node_modules/@types/d3-selection/index.d.ts(36,27): error TS2304: Cannot find name 'Node'.
../node_modules/@types/d3-selection/index.d.ts(36,34): error TS2304: Cannot find name 'Node'.
../node_modules/@types/d3-selection/index.d.ts(37,28): error TS2304: Cannot find name 'Node'.
../node_modules/@types/d3-selection/index.d.ts(37,44): error TS2304: Cannot find name 'Node'.
../node_modules/@types/d3-selection/index.d.ts(37,51): error TS2304: Cannot find name 'Node'.
../node_modules/@types/d3-selection/index.d.ts(38,39): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-selection/index.d.ts(39,42): error TS2304: Cannot find name 'NodeListOf'.
../node_modules/@types/d3-selection/index.d.ts(39,53): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-selection/index.d.ts(45,32): error TS2304: Cannot find name 'HTMLElement'.
../node_modules/@types/d3-selection/index.d.ts(45,46): error TS2304: Cannot find name 'SVGSVGElement'.
../node_modules/@types/d3-selection/index.d.ts(45,62): error TS2304: Cannot find name 'SVGGElement'.
../node_modules/@types/d3-selection/index.d.ts(110,110): error TS2304: Cannot find name 'HTMLElement'.
../node_modules/@types/d3-selection/index.d.ts(142,113): error TS2304: Cannot find name 'HTMLElement'.
../node_modules/@types/d3-selection/index.d.ts(873,43): error TS2304: Cannot find name 'HTMLElement'.
../node_modules/@types/d3-selection/index.d.ts(977,61): error TS2304: Cannot find name 'TouchList'.
../node_modules/@types/d3-selection/index.d.ts(989,64): error TS2304: Cannot find name 'TouchList'.
../node_modules/@types/d3-selection/index.d.ts(1013,29): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-selection/index.d.ts(1025,15): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-selection/index.d.ts(1033,18): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-selection/index.d.ts(1040,15): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-selection/index.d.ts(1040,35): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-selection/index.d.ts(1108,33): error TS2304: Cannot find name 'Window'.
../node_modules/@types/d3-selection/index.d.ts(1108,42): error TS2304: Cannot find name 'Document'.
../node_modules/@types/d3-selection/index.d.ts(1108,53): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-selection/index.d.ts(1108,63): error TS2304: Cannot find name 'Window'.
../node_modules/@types/d3-selection/index.d.ts(1122,44): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-selection/index.d.ts(1133,45): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-selection/index.d.ts(1154,46): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-selection/index.d.ts(1163,49): error TS2304: Cannot find name 'Element'.
../node_modules/@types/d3-selection/index.d.ts(1163,97): error TS2304: Cannot find name 'NodeListOf'.
../node_modules/@types/d3-shape/index.d.ts(304,16): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(312,22): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(757,16): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(765,22): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(935,16): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(943,22): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(1230,16): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(1238,22): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(1536,16): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(1544,22): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(1650,15): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(1686,15): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(2016,16): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(2024,22): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(2196,16): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(2204,22): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(2273,19): error TS2304: Cannot find name 'CanvasPathMethods'.
../node_modules/@types/d3-shape/index.d.ts(2358,16): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-shape/index.d.ts(2366,22): error TS2304: Cannot find name 'CanvasRenderingContext2D'.
../node_modules/@types/d3-transition/index.d.ts(572,65): error TS2304: Cannot find name 'HTMLElement'.
../node_modules/@types/d3-transition/index.d.ts(583,104): error TS2304: Cannot find name 'HTMLElement'.
../node_modules/@types/d3-zoom/index.d.ts(20,37): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(33,29): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(37,19): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(54,28): error TS2304: Cannot find name 'Node'.
../node_modules/@types/googlemaps/index.d.ts(788,30): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(799,36): error TS2304: Cannot find name 'Node'.
../node_modules/@types/googlemaps/index.d.ts(812,26): error TS2304: Cannot find name 'Node'.
../node_modules/@types/googlemaps/index.d.ts(1136,20): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1137,22): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1138,18): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1139,22): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1140,23): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1141,23): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1142,29): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1143,24): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1220,21): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1225,25): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1236,17): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1653,32): error TS2304: Cannot find name 'Node'.
../node_modules/@types/googlemaps/index.d.ts(1668,64): error TS2304: Cannot find name 'Document'.
../node_modules/@types/googlemaps/index.d.ts(1668,75): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1669,27): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1692,64): error TS2304: Cannot find name 'Document'.
../node_modules/@types/googlemaps/index.d.ts(1692,75): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1693,27): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1709,64): error TS2304: Cannot find name 'Document'.
../node_modules/@types/googlemaps/index.d.ts(1709,75): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1710,27): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1941,32): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(1942,28): error TS2304: Cannot find name 'Node'.
../node_modules/@types/googlemaps/index.d.ts(2394,36): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(2398,29): error TS2304: Cannot find name 'Element'.
../node_modules/@types/googlemaps/index.d.ts(2455,37): error TS2304: Cannot find name 'HTMLInputElement'.
../node_modules/@types/googlemaps/index.d.ts(2616,40): error TS2304: Cannot find name 'HTMLDivElement'.
../node_modules/@types/googlemaps/index.d.ts(2663,37): error TS2304: Cannot find name 'HTMLInputElement'.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ build: `tsc`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the functions@ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     [PATH ON LOCAL MACHINE]\AppData\Roaming\npm-cache\_logs\2018-04-19T16_10_21_812Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code2```
@laurenzlong
Copy link
Contributor

@laurenzlong laurenzlong commented Apr 20, 2018

If you ran npm run build inside your functions folder, does it succeed?

@dylanjmcdonald
Copy link
Author

@dylanjmcdonald dylanjmcdonald commented Apr 20, 2018

If you ran npm run build inside your functions folder, does it succeed?

It does not. Same error.

@laurenzlong
Copy link
Contributor

@laurenzlong laurenzlong commented Apr 20, 2018

Then it's something to do with your TypeScript set up or how you import modules inside your code. It's not a bug with firebase-tools.

@dylanjmcdonald
Copy link
Author

@dylanjmcdonald dylanjmcdonald commented Apr 20, 2018

@laurenzlong Ok, thanks for taking the time to help me out on this one. I guess I'm wondering why the firebase cloud functions even cares about which packages I include in my application. I've created a simplified demonstration on the error that I'm receiving. The cloud functions build fine until I include some type definitions such as @types/googlemaps. I would think that the cloud functions should build regardless of any type definition packages I include in the root level of this demonstration.

@laurenzlong
Copy link
Contributor

@laurenzlong laurenzlong commented Apr 20, 2018

"npm run build" uses regular "tsc" to build your files. This has nothing to do with Firebase or Cloud Functions.

@dylanjmcdonald
Copy link
Author

@dylanjmcdonald dylanjmcdonald commented Apr 20, 2018

@laurenzlong Thanks again! That helped me track down what I needed to do to solve my issue.

To anyone else running into this issue - I was able to get the functions to build successfully by modifying the functions build script to use tsc --skipLibCheck instead of tsc from within functions/package.json. This tells the typescript compiler to skip type checking of all declaration files.

@richard-joseph-dunelm
Copy link

@richard-joseph-dunelm richard-joseph-dunelm commented May 1, 2018

@dylanjmcdonald or put it in the tsconfig.json file:

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

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

Thanks for the heads up, btw 👍

@kyleabens
Copy link

@kyleabens kyleabens commented Jul 7, 2018

But what if you don't want to skip checking the declaration? In one of my cloud functions I use Objects.entries() which is es2017. I set it in tsconfig.json but because it's skipping it it throws an error when the function is executed. Any other way around this?

@gongevangen
Copy link

@gongevangen gongevangen commented Jul 16, 2018

I fixed the same problem by adding:
"typeRoots": [
"./functions/node_modules/@types"
]
to the tsconfig.json in functions folder

@Garviell
Copy link

@Garviell Garviell commented Jul 25, 2018

This happens with the stock autogenerated typescript when functions are initialized for me.

Just the autogenerated code and imports that are exactly like they are in the examples.

It seems to be because tsc will look for types up your process tree and tries to typecheck everything in the @types files but nothing else so things go to shit?

I think the most correct solution to this is to do as Gongevangen suggested. add "node_modules/@types" to typeRoots so that the module resolution algorithm doesn't go nuts up the tree.

@sidymbengue25
Copy link

@sidymbengue25 sidymbengue25 commented Aug 9, 2018

I got the same issus thanks to @dylanjmcdonald I have solved it by using tsc --skipLibCheck

@K1ngjulien
Copy link

@K1ngjulien K1ngjulien commented Sep 4, 2018

@dylanjmcdonald tsc --skipLibCheck in ./functions/package.json worked for me, thanks!

@yamitzky
Copy link

@yamitzky yamitzky commented Oct 14, 2018

I fixed by adding "dom" to compilerOptions.lib in ./functions/tsconfig.json .

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

@tomcatbuzz
Copy link

@tomcatbuzz tomcatbuzz commented Oct 24, 2018

This should work also. I used @yamitzky solution and worked for a function deploy. The below is usable as per a google dev's code I viewed.
{ "compilerOptions": { "lib": ["es6"], "module": "commonjs", "noImplicitReturns": true, "outDir": "lib", "sourceMap": true, "target": "es6", "skipLibCheck": true, "typeRoots": ["./functions/node_modules/@types"] }, "compileOnSave": true, "include": [ "src" ] }

@corcorb
Copy link

@corcorb corcorb commented Nov 1, 2018

It's great that there are work-arounds for this this, but one of these solutions should really be in the .tsconfig generated by firebase init. Does anyone know how we can get this issue reopened?

@bkendall
Copy link
Contributor

@bkendall bkendall commented Nov 1, 2018

You could re-open this issue, but I can tell you that we probably won't be adding dom to the lib property of the template tsconfig.json. It's meant as a minimum to get a developer off the ground and that default doesn't need dom. If you feel strongly otherwise, please feel free to open a pull request on this repo changing the templates, but I don't think it's a change we would make.

@phuduong060196
Copy link

@phuduong060196 phuduong060196 commented Nov 9, 2018

Thanks sir

@bbmk
Copy link

@bbmk bbmk commented Apr 18, 2019

Make sure that your .ts file is same name as .js in lib and also include it in package.json

@evanb2
Copy link

@evanb2 evanb2 commented Jul 21, 2019

Just to clarify @gongevangen 's solution works but make sure to place the "typeRoots" key inside "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"
  ],
}

Kinda confused as to why this wouldn't be included in the boilerplate...or even mentioned anywhere in any of the Firebase tuts.

@davepwsmith
Copy link

@davepwsmith davepwsmith commented Jan 21, 2020

I agree with @evanb2 - this just cost me an hour! Surely it would be worth at least mentioning it here: https://firebase.google.com/docs/functions/typescript if not including it in firebase init?

@oseiasmribeiro
Copy link

@oseiasmribeiro oseiasmribeiro commented Jan 26, 2020

God bless you Evanb2! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet