I am trying to set up a project for Google Apps Script with Typescript and Webpack.
I run into an odd error that I don't understand:
TS2451: Cannot redeclare block-scoped variable 'global'
global
is used by the gas-webpack-plugin
to create accessible functions in Google Apps Script.
I use it here in my entry point for webpack (index.ts
):
declare let global: any;
global.banana = () => {
// Method used in Google Apps Script
};
I get this error, but I'm not sure where I am redeclaring global
. I tried excluding node_modules
from tsconfig.json
:
{
"compilerOptions": {
"sourceMap": true,
"target": "es5",
"module": "es2015"
},
"exclude": [
"node_modules"
],
}
If I add an import before the declare line the error goes away. The content of import doesn't seem to matter. This is what I added. import { Whatever } from './whatever';
whatever.ts
contents:
export class Whatever {
static whatever(): string {
return "Nothing makes sense";
}
}
Clearly I have a workaround, just wondering why script stops with the error?