I have the following typescript files
src/main.ts
function main(): void {
console.log('main');
hello();
}
src/other.ts
console.log('hello world');
}
which generates the following in my Google App Project src/main.gs
var module = module || { exports: exports };
//import {hello} from "./other";
function main() {
console.log('main');
(0, other_1.hello)();
}
src/other.gs
var exports = exports || {};
var module = module || { exports: exports };
exports.hello = void 0;
function hello() {
console.log('hello world');
}
exports.hello = hello;
When I try to run the the main()
function in main.gs
I get the following error:
How can I make imports work in a clasp project?
Modification points:
From
//import {hello} from "./other";
and(0, other_1.hello)();
, I'm worried that in this case, the reason for your current issue might be due to that Google Apps Script doesn't supportimport
yet.And also, in the case of Google Apps Script, for example, when
function hello() {console.log("hello world");}
is put into a script file ofother.gs
, this function can be directly called from another script file likemain.gs
.From these points, how about the following modification patterns?
Pattern 1:
main.ts
other.ts
main
is run,console.log("main")
inmain
function andconsole.log("hello world")
inhello
function are run with the script editor of Google Apps Script.Pattern 2:
In this pattern, the Class object is used.
main.ts
other.ts
main
is run,console.log("main")
inmain
function andconsole.log("hello world")
inhello
function are run with the script editor of Google Apps Script.