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

sst-env.d.ts Generation Missing Export in Monorepo Workspace #4523

Closed
isaac-scarrott opened this issue Jun 13, 2024 · 11 comments
Closed

sst-env.d.ts Generation Missing Export in Monorepo Workspace #4523

isaac-scarrott opened this issue Jun 13, 2024 · 11 comments
Assignees

Comments

@isaac-scarrott
Copy link

Hey,

I'm seeing an issue with sst-env.d.ts in my monorepo. I have two sst-env.d.ts files being generated, one in the root and one in my cloudflare worker folder/workspace.

The root sst-env.d.ts seems to be correct and look something like the following:

/* tslint:disable */
/* eslint-disable */
import "sst"
declare module "sst" {
  export interface Resource {
    Api: {
      type: "sst.cloudflare.Worker"
      url: string
    }
  }
}
export {}

However, the sst-env.d.ts generated in my app/workspace folder seems to be causing an issue as it does not have export {} at the end and is causing the error 'Resource' only refers to a type, but is being used as a value here when attempting to reference the resource

Also note that this is a project deployed to cloudflare.

@isaac-scarrott
Copy link
Author

Please let me know if you wish me to create a minimal repository to reproduce this issue

@jayair
Copy link
Contributor

jayair commented Jun 25, 2024

We made some changes to this recently, can you update your CLI?

Also have a look at how our monorepo example has it: https://github.com/sst/ion/blob/dev/examples/aws-monorepo/packages/functions/sst-env.d.ts & https://github.com/sst/ion/blob/dev/examples/aws-monorepo/sst-env.d.ts

Lmk if that helps.

@jayair jayair self-assigned this Jun 25, 2024
@isaac-scarrott
Copy link
Author

Hey @jayair, upgrading didn't help unfortunately and I'm following the examples correct. I believe it's this commit and specifically this line that has caused this to happen.

I believe the fix would be to add export {}, to the line after this one would fix this issue. Similar to how there is this line here for the root sst-env.d.ts that enables all of my non cloudflare resources to pass the type checks.

I would test this locally and raise a PR however, I can't work out how to run the CLI locally so if I could get some guidance on how to run it locally or someone else could fix it that would be great

@jayair jayair assigned thdxr and unassigned jayair Jul 4, 2024
@kleenkanteen
Copy link
Contributor

kleenkanteen commented Jul 8, 2024

I get the same error but when following https://ion.sst.dev/docs/start/aws/hono/. I am on a fresh github codespace with 8gb ram.

@kleenkanteen
Copy link
Contributor

kleenkanteen commented Jul 9, 2024

I was able to bypass these issues by installing a 2 month old version of ion and the sst npm package.

I did these steps:

  1. rm -rf .sst in the current directory
  2. ion cli linux install: curl -fsSL https://ion.sst.dev/install | VERSION=0.0.337 bash
  3. pnpm install sst@3.0.19

@kleenkanteen
Copy link
Contributor

kleenkanteen commented Jul 9, 2024

Ok I stopped sst dev on accident, then reran it, and I get this cryptic error, different than the original error I was getting like OP:

@kleenkanteen ➜ /workspaces/YT-Sub-Steroids/backend (sst-backend) $ sst dev --verbose
time=2024-07-09T06:42:48.811Z level=INFO msg="checking for pulumi" path=/home/codespace/.config/sst/bin/pulumi
time=2024-07-09T06:42:49.442Z level=INFO msg="checking for bun" path=/home/codespace/.config/sst/bin/bun
time=2024-07-09T06:42:49.461Z level=INFO msg=args args=[] length=0
time=2024-07-09T06:42:49.464Z level=INFO msg="no existing server found, starting new one"
time=2024-07-09T06:42:49.473Z level=INFO msg="waiting for server to start"
time=2024-07-09T06:42:49.575Z level=INFO msg="checking for pulumi" path=/home/codespace/.config/sst/bin/pulumi
time=2024-07-09T06:42:50.266Z level=INFO msg="checking for bun" path=/home/codespace/.config/sst/bin/bun
time=2024-07-09T06:42:50.294Z level=INFO msg="initializing project" version=0.0.337
time=2024-07-09T06:42:50.294Z level=INFO msg="esbuild building"
time=2024-07-09T06:42:51.167Z level=INFO msg="esbuild built" outfile=/workspaces/YT-Sub-Steroids/backend/.sst/eval/eval-1720507370294.mjs
time=2024-07-09T06:42:51.167Z level=INFO msg="evaluating config"
time=2024-07-09T06:42:51.440Z level=INFO msg="config evaluated"
time=2024-07-09T06:42:51.440Z level=ERROR msg="exited with error" err="Error evaluating config: exit status 1\nfile:///workspaces/YT-Sub-Steroids/backend/.sst/eval/eval-1720507370294.mjs:33\nvar bucket = new sst.aws.Bucket(\"MyBucket\", {\n             ^\n\nReferenceError: sst is not defined\n    at file:///workspaces/YT-Sub-Steroids/backend/.sst/eval/eval-1720507370294.mjs:33:14\n    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)\n    at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)\n    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)\n\nNode.js v20.14.0\n"
×  Unexpected error occurred. Please check the logs or run with --verbose for more details.
time=2024-07-09T06:42:51.442Z level=ERROR msg="exited with error" err="exit status 1"

@kleenkanteen
Copy link
Contributor

Ok somehow moving this part to inside the run() function solved my issue:

const bucket = new sst.aws.Bucket("MyBucket", {
        public: true
        });            

@thdxr
Copy link
Contributor

thdxr commented Jul 17, 2024

@isaac-scarrott sorry having a bit of trouble following

can you show me a full example of what is being generated?

@isaac-scarrott
Copy link
Author

isaac-scarrott commented Jul 17, 2024

@thdxr Yes of course, I can also try to reproduce in a separate public repo if that will help?

Outputs are as follows:

sst-env.d.ts:

/* tslint:disable */
/* eslint-disable */
import "sst"
declare module "sst" {
  export interface Resource {
    AblyApiKey: {
      type: "sst.sst.Secret"
      value: string
    }
    ClerkJwtVerificationKey: {
      type: "sst.sst.Secret"
      value: string
    }
    ClerkPublishableKey: {
      type: "sst.sst.Secret"
      value: string
    }
    ClerkSecretKey: {
      type: "sst.sst.Secret"
      value: string
    }
    ContentProcessorQueue: {
      type: "sst.aws.Queue"
      url: string
    }
    HuggingFaceAccessToken: {
      type: "sst.sst.Secret"
      value: string
    }
    Main: {
      type: "sst.cloudflare.Worker"
      url: string
    }
    OpenAiApiKey: {
      type: "sst.sst.Secret"
      value: string
    }
    OpenAiOrgId: {
      type: "sst.sst.Secret"
      value: string
    }
  }
}
export {}

apps/api/sst-env.d.ts:

/* tslint:disable */
/* eslint-disable */
/// <reference path="../../sst-env.d.ts" />
// cloudflare 
declare module "sst" {
  export interface Resource {
    ContentAssetBucket: import("@cloudflare/workers-types").R2Bucket
    Database: import("@cloudflare/workers-types").D1Database
  }
}

If I append export {} to apps/api/sst-env.d.ts all types are available through sst's Resource object. Without this I cannot access anything on sst's Resource object

@thdxr
Copy link
Contributor

thdxr commented Jul 17, 2024

gotcha - should be fixed in v0.0.540

@thdxr thdxr closed this as completed Jul 17, 2024
@isaac-scarrott
Copy link
Author

Thanks @thdxr !

@thdxr thdxr transferred this issue from sst/ion Oct 21, 2024
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

4 participants