<@U01JVDKASAC> We have an NPM package where we hav...
# help
t
@Frank We have an NPM package where we have a lot of utility functions we use across multiple apps. I have attempted to put an SST stack into that package, but as soon as I include any form of "import { ... } from '<our package>';", resulting Lambda functions fail to execute when deployed (via Seed) with an error:
Copy code
"Error: Cannot find module 'punycode/'\nRequire stack:\n- /var/task/src/lambda.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js"
Oddly, when testing the function locally, it works fine, but when deployed via Seed, it does not. I am lost as to where to go look to resolve this. Any suggestions?
t
it's likely the way you're bundling things is leaking stacks code into your runtime function
punycode is a dependency of aws-cdk
and with your setup esbuild isn't able to treeshake it, how are you importing your shared code in your function from your package?
t
I saw your other reply to someone else where they were getting a lot of extra code because of an index file exporting many things.
Like this:
Copy code
export { utility } from './utility';

// Responses for REST API endpoints
export { response, HttpResponse } from './response';

// Default service endpoints
export { main as delete } from './endpoints/delete';
export { main as get } from './endpoints/get';
export { main as list } from './endpoints/list';
export { main as reindex } from './endpoints/reindex';
export { main as search } from './endpoints/search';
export { main as upsert } from './endpoints/upsert';
<... and more>
We added the SST exports in that same file, so perhaps that's combining them all into a single massive blob?
t
yeah so with esbuild it doesn't treeshake if you import from an index file, it's a limitaiton that kinda sucks
so I stopped creating index fiels and I now import from the subpath
I use to have
import { Thing } from "@company/core"
and now I do
import { Thing } from "@company/core/thing"
t
I moved the exports out of that file and it fixed the problem! So that's amaze-balls.
After a day and half of messing with this one problem.
t
yeah it took me a lot of focused testing with esbuild to understand this. hopefully one day it gets import treeshaking
t
So I need to rethink how I organize the utility package and then import those functions directly without an index file.
it's the re-exporting specifically it has trouble with
t
There you go. Thank you!