Requiring tslib in transpiled code
furious-luke opened this issue · comments
Hi there! Firstly, thanks a tonne for this great utility and all your hard work, it's much appreciated.
I've been using Google's clasp
to push TypeScript based Apps Scripts projects, and it was working as expected for a couple of weeks. Then recently I've found that the conversion from TypeScript has begun generating gas code that doesn't work. It seems that there is a line in the transpiled code as follows:
var tslib_1 = require("tslib");
This throws an error as require
isn't supported. I can see that it seems to be related to using the following features (but not limited to them):
- async/await
- async generators
- rest operators
I did a little digging through my previous transpilations that worked, and I can see that in those instances the required polyfills from tslib
were being injected into the transpiled code.
Do you have any thoughts on what may be happening here? Could it be an issue related to clasp
and not ts2gas
?
The fact that any tslib
import/require show up in your code is an indication that there is something wrong in you typescript configuration. Most likely this is linked to the script engine you are targeting. By default, ts2gas
use setup for the legacy Rhino engine. It is possible to setup your clasp project to target the newer V8 engine. I am unsure where it is properly documented, but you can check it here: google/clasp#735
Now my advice is to avoid using ts2gas
altogether. Take a look at the project template below for a V8 engine, Typescript project where compilation is handled before invoking clasp
https://github.com/PopGoesTheWza/ts-gas-project-starter
Last, because of some issue with the owner of the @google/clasp
npm package, the latest fixes and improvement are available through the forked-clasp
npm releases:
npm uninstall -g @google/clasp
npm install -g forked-clasp
@PopGoesTheWza Thanks so much for your reply, that's incredibly helpful! You're correct, the issue was related to my tsconfig.json
setup. I needed to modify the target
and lib
settings to ensure polyfills were injected.
Again, thanks for your response!