Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENV is not defined #9

Open
jhches21 opened this issue Oct 23, 2023 · 4 comments
Open

ENV is not defined #9

jhches21 opened this issue Oct 23, 2023 · 4 comments

Comments

@jhches21
Copy link

Good day. I was browsing through GitHub for anything related to GAS and your project caught my eye and I wanted to give it a spin.

I was able to create a new script, build the app successfully using npm run build, and clasp push it to the new script that I just created.

I hit this problem when opening it as a Webapp.

ReferenceError: ENV is not defined (line 12, file "server/lib/initializeApp_")

I looked all over the code and while it all seems correct to me, I'm not sure why on earth the server/env.gs wasn't initializing. Maybe you have any idea why?

Looking forward to trying this project out!

@jhches21
Copy link
Author

I went on and added

ENV = {
    executeAs: "USER_DEPLOYING",
    domain: {
        type: "Personal",
        name: "",
    },
};

to the server/lib/initializeApp_.gs in the Google Apps Script directly, right above the initializeApp_ function and it works.

So, somehow the code in server/env.gs isn't working.

// Compiled using gas-svelte-app 0.0.0 (TypeScript 4.9.5)
var exports = exports || {};
var module = module || { exports: exports };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ENV = void 0;
exports.ENV = {
    executeAs: "USER_DEPLOYING",
    domain: {
        type: "Personal",
        name: "",
    },
};

@mikedownesdev
Copy link
Owner

Hey @jhches21 ! First off thanks for opening this issue! I'm new-ish to open source discussions and I was really pumped to see someone was trying to out the template.

You're exactly right about the server/env.gs not working. One of the difficulties I've been wrangling is how to handle the compilation step so that variables (like ENV) and functions are scoped in a way that's predictable. I've had some late nights trying to figure this out and I'm still working at it.

I'm working on a solution for this, whether its fixing the compilation from Typescript (hopefully) or re-thinking the ENV variable altogether. When I've done so I'll close this issue.

@jhches21
Copy link
Author

jhches21 commented Oct 23, 2023

Thanks for the comment!

I was only able to test this once, but apparently, you had a link somewhere in the codebase that lead me to this https://stackoverflow.com/questions/48791868/use-typescript-with-google-apps-script

I decided to modify the src/env.ts to this

type EnvironmentDetails = {
  executeAs: "USER_DEPLOYING" | "USER_ACCESSING";
  domain: {
    type: "Personal" | "Workspace";
    name: string;
  };
};

const ENV: EnvironmentDetails = {
  executeAs: "USER_DEPLOYING", // "USER_DEPLOYING" | "USER_ACCESSING"
  domain: {
    type: "Personal",
    name: "",
  },
};

export { ENV };

And it seems to work very well.

Edit: it was from schemas.ts

@Hunteraulo1
Copy link

Hi, no solution found ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants