Where `clasp` puts `.gs` files? Troubleshooting compiler errors on `clasp push`

295 Views Asked by At

Where locally can I find the .gs files that clasp push generates?

I'm using clasp push to compile a TypeScript file into a .gs file and upload it to Apps Script, but I'm getting an error:

$ clasp push                                                                                                                    
| Pushing files...Push failed. Errors:                                                                                                                 
{ Error: Syntax error: ParseError: Unexpected token . line: 253 file: Code.gs

The line number in the error is in terms of the compiled .gs file, which does not get uploaded because of the error. I need to find the compiled local copy of the .gs file so I can inspect it and fix the error in the original .ts typescript file, but where is the .gs file?

My TypeScript file compiles without errors using tsc.

2

There are 2 best solutions below

0
On

Workaround:

Compile the typescript file, say Code.ts, into javascript yourself using tsc.

Then validate the resulting local Code.js, for example by

  • Pasting its contents into the Code.gs file in the Apps Script code editor. When you hit save, you'll hopefully see the same error.
  • Or, with node --check Code.js

This will show you an error in terms of a file that you have access to.

0
On

Don't rely on @google/clasp for compiling your typescript into .gs

Trust me (as a major contributor to clasp) you'll be best by handling the compilation yourself, with clasp only being used to push your compiled files.

I have a github template which may get you started: https://github.com/PopGoesTheWza/ts-gas-project-starter