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

Function deploy error: tsc: not found #2589

Closed
svprdga opened this issue Sep 1, 2020 · 4 comments
Closed

Function deploy error: tsc: not found #2589

svprdga opened this issue Sep 1, 2020 · 4 comments

Comments

@svprdga
Copy link

svprdga commented Sep 1, 2020

[REQUIRED] Environment info

firebase-tools: 8.5.0

Platform: Linux Mint

[REQUIRED] Test case

I am trying to upload a schedule function following this guide: https://firebase.google.com/docs/functions/schedule-functions

[REQUIRED] Steps to reproduce

I have the following package.json:

{
  "name": "functions",
  "version": "1.2.0",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log",
    "test": "mocha -r ts-node/register src/**/*.spec.ts"
  },
  "engines": {
    "node": "10"
  },
  "main": "lib/index.js",
  "dependencies": {
    "axios": "^0.20.0",
    "firebase-admin": "^9.1.1",
    "firebase-functions": "^3.11.0",
    "ts-mailgun": "^0.4.2"
  },
  "devDependencies": {
    "@types/axios": "^0.14.0",
    "@types/chai": "4.2.12",
    "@types/mocha": "8.0.3",
    "@types/sinon": "9.0.5",
    "chai": "4.2.0",
    "firebase-functions-test": "^0.2.1",
    "mocha": "^8.1.3",
    "sinon": "9.0.3",
    "ts-node": "9.0.0",
    "tslint": "^6.1.3",
    "typescript": "^4.0.2"
  },
  "private": true
}

My tsconfig.json:

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

I try to upload the function with the command:
firebase deploy --only functions:testServer --project=pro

[REQUIRED] Expected behavior

The function is deployed successfully.

[REQUIRED] Actual behavior

Deploy error with the output:

[...]
i  functions: updating Node.js 10 function testServer(us-central1)...
i  scheduler: ensuring required API cloudscheduler.googleapis.com is enabled...
i  pubsub: ensuring required API pubsub.googleapis.com is enabled...
✔  scheduler: required API cloudscheduler.googleapis.com is enabled
✔  pubsub: required API pubsub.googleapis.com is enabled
✔  functions: created scheduler job firebase-schedule-testServer-us-central1
⚠  functions[testServer(us-central1)]: Deployment error.
Build failed: > protobufjs@6.10.1 postinstall /workspace/node_modules/protobufjs
> node scripts/postinstall


> ts-mailgun@0.4.2 postinstall /workspace/node_modules/ts-mailgun
> tsc --p tsconfig.dist.json

sh: 1: tsc: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! ts-mailgun@0.4.2 postinstall: `tsc --p tsconfig.dist.json`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the ts-mailgun@0.4.2 postinstall 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!     /builder/home/.npm/_logs/2020-09-01T15_29_48_863Z-debug.log; Error ID: 49341d49


Functions deploy had errors with the following functions:
        testServer


To try redeploying those functions, run:
    firebase deploy --only functions:testServer


To continue deploying other features (such as database), run:
    firebase deploy --except functions

Error: Functions did not deploy properly.

I have tried the solutions provided in the following threads without success:
#749
https://stackoverflow.com/questions/54498868/firebase-deploy-returns-error-at-tsc-command
#2513

@samtstern
Copy link
Contributor

samtstern commented Sep 3, 2020

@svprdga this is not an issue with Firebase it's an issue with the ts-mailgun library which seems to require tsc in its postinstall step:
https://github.com/StatelessStudio/ts-mailgun/blob/master/package.json#L21

Afaik this is not a best practice, ts-mailgun should be distributing JS sources and not requiring each client to compile the TypeScript.

One workaround you could do is move typescript from your devDependencies to your dependencies so that tsc is available when your Cloud Functions image is built. Although this is not really ideal ... you should bring this issue up with the maintainers of ts-mailgun and see if they can fix it.

@samtstern
Copy link
Contributor

@svprdga it looks like others have already reported this issue:
StatelessStudio/ts-mailgun#36

@svprdga
Copy link
Author

svprdga commented Sep 3, 2020

OK, I have already changed the library so I no longer have this problem. Thanks.

@DrewImm
Copy link

DrewImm commented Sep 13, 2020

This issue is fixed in ts-mailgun@0.4.3. Thanks

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

No branches or pull requests

3 participants