I have multiple files in my apps script project. Some of them are library files that provide utility functions for a larger app. How can I import them into my main file?
For example, in Node, I would be able to import update-cell-1.gs
and update-cell-2.gs
into my main.gs
file like this:
// update-cell-1.gs
export default function() {
// code to update cell 1
}
// update-cell-2.gs
export default function() {
// code to udpate cell 2
}
// main.gs
import updateCell1 from "update-cell-1.gs";
import updateCell2 from "update-cell-2.gs";
function main() {
updateCell1();
updateCell2();
}
main();
What is the equivalent in apps script?
When I try using module.exports, I get this error:
ReferenceError: module is not defined
When I try using export default
, I get this error:
SyntaxError: Unexpected token 'export'
CodePudding user response: