google / clasp

đź”— Command Line Apps Script Projects
https://developers.google.com/apps-script/guides/clasp
Apache License 2.0
4.53k stars 424 forks source link

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

Open haohaolee opened 4 years ago

haohaolee commented 4 years ago

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

erickoledadevrel commented 4 years ago

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.

PopGoesTheWza commented 4 years ago

@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…

haohaolee commented 4 years ago

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

PopGoesTheWza commented 4 years ago

@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?