问题
I am having an issue with a script that references a library. My issue is not connecting to the library, its that my script calls a function, but when it runs, it errors out on a function that I am not referencing.
In sheet A, I have this code:
function DataPull() {
MasterScriptLibrary.DataPullBillable()
}
In MasterScriptLibrary (project's full name is 2020 Master Script Library), I have 2 distinct functions (they don't reference each other at all) called convertPersonnel and DataPullBillable.
When the above function runs from sheet A, I get an error message:
Syntax error. (line 66, file "convertPersonnel", project "2020 Master Script Library")
Line 66 of the library:
var data = activeRange.filter(element => element.join("") != "");
Any idea what could be happening here?
回答1:
Problem
When a library is required in Google Apps Script project, it is run in the environment of the calling script. Thus, if any of the language features / syntax used by the library are not supported by the runtime of the calling script, it will throw a corresponding error.
Runtimes
One of the most common issues since GAS switched from Rhino to V8 runtime is caused by trying to use ES6 features (some were supported even in the older one, but the comprehensive list is gone from the developers resource since the overhaul).
Syntax Error
You are trying to use syntax not supported in the older runtime, hence the SyntaxError. The message points directly to the issue (line 66) but does not provide info on what is wrong, so the confusion is understandable (the fact that it is valid ES6 syntax adds to it).
The actual problem is the presence of an arrow function.
Check for runtime
To check which runtime is used (apart from the plaque at the top if using script editor), open manifest file (appsscript.json) and find the runtimeVersion field, it will be set to either "V8" or "DEPRECATED_ES5" (Rhino).
Newer scripts are guaranteed to use V8, but you have to migrate older ones manually by either setting the abovementioned field to V8 (you can also "downgrade" as needed) or selecting the option in "Run" menu.
来源:https://stackoverflow.com/questions/61897189/script-error-on-internal-function-when-calling-another-function-in-a-library