sst / sst

SST v2
https://v2.sst.dev
MIT License
21.53k stars 1.63k forks source link

Local function invocation fails with 'Could not resolve "proxy-agent"' with certain Config resources present #2904

Open tobz1000 opened 1 year ago

tobz1000 commented 1 year ago

It's difficult to find a minimum reproduction of this one.

When I include certain Config resource definitions in my infra code, the following error occurs, after building, when invoking a function via the console:

|  Invoked ./api/session/src/endpoints/remember.handler

✖  Build failed ./api/session/src/endpoints/remember.handler
   Could not resolve "proxy-agent"
   ../../node_modules/sst-aws-cdk/lib/api/aws-auth/sdk-provider.js
   311 │     const ProxyAgent = require('proxy-agent');

|  Invoked ./api/session/src/endpoints/remember.handler

✖  Build failed ./api/session/src/endpoints/remember.handler
   Error: The service was stopped

Workaround: Install proxy-agent as a devDependency of the affected infra project. I can see it's a devDependency of sst-aws-cdk, so maybe it should be a regular dependency instead. I haven't digged into that relationship much though.


Some more detail on how my infra code reproduced the bug below.

I'm attempting to create a stack specifically for config variables, which are then consumed by multiple other stacks, e.g.:

// ConfigStack.ts
import { Config, type StackContext } from 'sst/constructs';

export function ConfigStack({ app, stack }: StackContext) {
    const apiKey = new Config.Secret(stack, "API_KEY");

    return { apiKey };
}

// FunctionStack.ts
import { type StackContext } from 'sst/constructs';
import { ConfigStack } from './ConfigStack';

export function FunctionStack({ app, stack}: StackContext) {
    const { apiKey } = use(ConfigStack);

    // Bind apiKey to other resources...
}

Importing a module with this code within my infra is enough to trigger the bug - I don't even have to include ConfigStack in my sst config nor import it in FunctionStack.

Stranger still, when there's no ConfigStack in my code and I include the Config.Secret definition directly FunctionStack, it works as expected. So maybe it's related to defining secrets and not binding them to anything within a stack...? Pure speculation though.

jayair commented 1 year ago

Might be esm or cjs related. Start a thread in #help on Discord?

tobz1000 commented 1 year ago

Thanks - I'm happy with the workaround for now. Just thought I should submit a bug report in case the fix is obvious/it's helpful to someone else.

vespertilian commented 1 year ago

@tobz1000 just encountered this, workaround is working.

@jayair So, I cannot log into discord on my work computer, I don't want to connect my work computer (managed by corporate) to my personal discord, but discord seems to only want me to sign up with a phone number not my work email. You can only use one phone number with one account, and the personal discord is already using it.

An open searchable forum that is not gated would be nice.

I guess I can browse on my personal phone... a bit awkward.

tobz1000 commented 1 year ago

An open searchable forum that is not gated would be nice.

Off-topic but I agree. It's strange for bug discussion to not be public/preserved within in issues directly. I kinda get it for personalised help, but some things are real bugs/feature requests.

jayair commented 1 year ago

Yeah it's just hard for us to have conversations spread out everywhere. We just found that people don't respond in time for a lot of issues. So they just fall through the cracks. On Discord we can jump on issues right away and fix them.

msolano00 commented 1 year ago

I'm experiencing a similar issue:

Build failed packages/functions/src/validateUser.handler
   Could not resolve "mock-aws-s3"
   node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js
   43 │     const AWSMock = require('mock-aws-s3');
   Could not resolve "nock"
   node_modules/@mapbox/node-pre-gyp/lib/util/s3_setup.js
   112 │   const nock = require('nock');
   Could not resolve "@aws-sdk/client-dynamodb"
   packages/functions/src/validateUser.js
   4 │ import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
   Could not resolve "@aws-sdk/lib-dynamodb"
   packages/functions/src/validateUser.js
   5 │ import { DynamoDBDocumentClient, GetCommand } from '@aws-sdk/lib-dynamodb';
jayair commented 1 year ago

This seems different, please post on Discord.

mikebrantbison commented 11 months ago

The original error noted above seems to relate to same error discussed here on Discord - https://discord.com/channels/983865673656705025/1116777988600631457/1116777988600631457