clasp icon indicating copy to clipboard operation
clasp copied to clipboard

Beginner Question: Why "no functions to run" for the official example?

Open haohaolee opened this issue 5 years ago • 4 comments

Hi all, I copied the official example from here

const greeter = (person: string) => {
  return `Hello, ${person}!`;
}

let user = 'Grant';
Logger.log(greeter(user));

Expected Behavior

I can run the example in the online editor and see the logs

Actual Behavior

The run button is gray with "No functions to run" tip image

Steps to Reproduce the Problem

just clasp push the code above

Specifications

  • Node version (node -v): v10.17.0
  • Version (clasp -v): 2.3.0
  • OS (Mac/Linux/Windows): Mac

haohaolee avatar Nov 16 '19 13:11 haohaolee

Apps Script requires that functions be declared at the top-level scope with the function keyword in order to be visible in the "Run" dropdown. Some developers use a webpack plugin to achieve this, and perhaps it should be built into clasp directly.

erickoledadevrel avatar Nov 18 '19 17:11 erickoledadevrel

@haohaolee please share a link to your google apps script project. @erickoledadevrel transpiled arrow function always end up as regular functions, and the original source seems to be in the global scope…

I still need to see one good use case for webpack with GAS. The only one I ever saw were klugy workaround for trying to mimick node/es modules…

PopGoesTheWza avatar Nov 18 '19 21:11 PopGoesTheWza

@PopGoesTheWza here is a demo for that https://github.com/haohaolee/clasp-test

haohaolee avatar Jan 17 '20 02:01 haohaolee

@haohaolee Just to be sure, did you paste the sample code directly into the online Google Apps Script editor or did you create a local clasp project, a .ts file with the sample code and then used clasp push?

PopGoesTheWza avatar Jan 20 '20 17:01 PopGoesTheWza