5

I have recently noticed a weird behaviour of the V8 engine. When inheriting a class found in a separated file, the engine fails to recognise the base class, e.g. the following configuration fails:

BaseFoo.ts

export class BaseFoo {}

SpecialFoo.ts

import { BaseFoo } from "./BaseFoo";

class SpecialFoo extends BaseFoo {}

with an error:

ReferenceError: BaseFoo is not defined [line: 1, function: , file: SpecialFoo]

If the two classes are put in the same file, it works.

I am using Visual Studio Code, and it approves this configuration (meaning no typo mistakes).

Any ideas?

A. Kali
  • 739
  • 6
  • 19

2 Answers2

2

As stated on their V8 Runtime page:

Caution: ES6 modules are not yet supported.

This means exporting and importing of files is not handled by Google Apps Script. This is a bit quirky since all files are in the global scope (and in the order the files are listed) and so you can reference Classes in other files.

Sunny Patel
  • 7,830
  • 2
  • 31
  • 46
  • 1
    If it helps, I have migrated a Library to V8 + Typescript: [grahamearley/FirestoreGoogleAppsScript](https://github.com/grahamearley/FirestoreGoogleAppsScript) that you can reference. I spent a lot of hours trying to get a lot of `Class` functionality working. I do have some inheritance happening too. – Sunny Patel Jun 23 '20 at 00:10
0

As mentioned by Sunny Patel, the V8 runtime does not support modules. However, you might look into Clasp and its TypeScript feature, which partially supports modules.

Related links:

coccoinomane
  • 858
  • 8
  • 24