1

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?

Stephen
  • 11
  • 2
  • Show all of the library files – TheMaster May 19 '20 at 17:33
  • Try naming the script "2020MasterScriptLibrary" and then refer to it's functions like this: 2020MasterScriptLibrary.functionName() – Cooper May 19 '20 at 18:31
  • The "convertPersonnel" script runs with no issues when I call it from "2020 Master Script Library", so I am not even sure how to fix a seemingly non-existent syntax error. The second line is supposedly the syntax error: var activeRange = ss.getRange(1, 19, masterRoster.length, 1).getValues(); var data = activeRange.filter(element => element.join("") != ""); – Stephen May 19 '20 at 19:42
  • 1
    [started comment before yours - the error really looks like using an arrow function in Rhino runtime] Agreed with TheMaster - you need to show how `convertPersonnel` is declared. There is a syntax error at line 66 of the library (the exact error message). If you think syntax is valid, check if you use ES6 features in non-V8 script, they result in syntax error. It would also be helpful if you show what identifier your library has in script manifest (although you should've received another error on mismatch). – Oleg Valter is with Ukraine May 19 '20 at 19:51
  • That said - what does the `1).getValues();` mean? Please, update the answer with exactly how line 66 of the library looks like – Oleg Valter is with Ukraine May 19 '20 at 19:55
  • 1
    line 65: var activeRange = ss.getRange(1, 19, masterRoster.length, 1).getValues(); line 66: var data = activeRange.filter(element => element.join("") != ""); – Stephen May 19 '20 at 20:03
  • thanks! Aaand `runtimeVersion` field of the manifest file of the library? – Oleg Valter is with Ukraine May 19 '20 at 20:05
  • 1
    the version is V8 – Stephen May 19 '20 at 20:10
  • Ok, thanks again, that eliminates the most obvious. Next: is the same (V8) true for your master script, just to make sure? Line 66 looks correct, so in my experience this 'syntax error" has the underlying issue of trying to run the ES6 script under Rhino runtime (tested). – Oleg Valter is with Ukraine May 19 '20 at 20:15
  • 1
    I think I figured it out based on your question! The master script file was V8, but "Sheet A" was not. Once I set them to the same version, the original script worked. – Stephen May 19 '20 at 20:20
  • Yep, that's the culprit right there :) Seems like your master script was created before the switch to V8, right? Newer ones won't have this problem at all. – Oleg Valter is with Ukraine May 19 '20 at 20:23
  • Yes it was, thank you for the help! – Stephen May 19 '20 at 20:24
  • We are glad to help - just as a rule of thumb if you see a cryptic "syntax error" in the project (without pointers to the exact issue) this is probably an unsupported ES6 feature – Oleg Valter is with Ukraine May 19 '20 at 20:28
  • 1
    Consider adding a answer. – TheMaster May 19 '20 at 21:11
  • 1
    @TheMaster - yep, thanks for suggesting, got distracted - this discussion is useful as error messages in GAS tend to invoke confusion if you don't know the reason already in my opinion – Oleg Valter is with Ukraine May 19 '20 at 22:53

1 Answers1

2

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.