uh oh, found another bug ```Error: Cannot find th...
# sst
t
uh oh, found another bug
Copy code
Error: Cannot find the esbuild config file at "/Users/tylerflint/Code/tylerflint/serverless-app-template/Users/tylerflint/Code/tylerflint/serverless-app-template/config/esbuild.js"
when using the config:
Copy code
esbuildConfig: {
        plugins: "config/esbuild.js"
      }
I have 4 functions defined, and the first compiles fine, whichever follows fails immediately.
my guess is there is a dangling reference somewhere.
from within `@serverless-stack/resources/src/util/nodeBuilder.ts`:
Copy code
// Validate custom esbuild plugins path
    if (customConfig && customConfig.plugins) {
      customConfig.plugins = path.join(appPath, customConfig.plugins);
      if (!fs.existsSync(customConfig.plugins)) {
        throw new Error(
          `Cannot find the esbuild config file at "${customConfig.plugins}"`
        );
      }
    }
customConfig.plugins
must get changed somewhere to the full path, which works on the first run, but on the second run it tries to concatenate again which creates a non-existent path
t
interesting
t
oh wait… the error is literally right there staring at me in that snippet
Copy code
customConfig.plugins = path.join(appPath, customConfig.plugins);
it’s using itself as part of the
path.join
the first time that works, the second time when using the same instantiated object, it will not work
t
yeah we shouldn't be mutating anything
There's a few places in our codebases where that's done
Copy code
let customConfig = appEsbuildConfig || bundle.esbuildConfig || {};
Quick fix would be to deep clone here
t
yep, check this out:
Copy code
Building Lambda function src/lambda/graphql.main
Before: config/esbuild.js
After: /Users/tylerflint/Code/tylerflint/serverless-app-template/config/esbuild.js

Building Lambda function src/lambda/web.main
Before: /Users/tylerflint/Code/tylerflint/serverless-app-template/config/esbuild.js
After: /Users/tylerflint/Code/tylerflint/serverless-app-template/Users/tylerflint/Code/tylerflint/serverless-app-template/config/esbuild.js
t
are you defining your esbuild config once and passing it to each function?
or are you using defaultFunctionProps
t
oh, yes I am…
no, not using defaultFunctionProps
t
we shouldn't break it if you do, I'm really anti-mutation in general for this reason so I'll fix this
t
yeah let me try that…
t
I meant we shouldn't be mutating user input
t
the only reason I went away from defaultFunctionProps is because I wanted to set the default function props for the current stack only, not the app
t
You can actually do that now
t
oh?
t
this.setDefaultFunctionProps
in the stack
t
oh, nice!
t
I do wonder if this will still have the same issue
t
let me give that a whirl…
no dice. It looks like it’s pulling that from the
sst.json
configuration, and not the function definition
I tried removing it from the
sst.json
config and only using the function definition and that didn’t seem to work
t
I think @Frank has more familiarity with how this works
t
meaning, it didn’t notice the custom esbuild config and failed to build
t
Let me fix the mutation problem right now and send you a test build
Can you try this version 0.43.10-next.19+1e86a933
t
yep…
doesn’t seem to have changed
let me look and verify that the new version is running
any earmarks to look for, specifically?
t
cat
./node_modules/@serverless-stack/resources/package.json
check the version
t
from the package.json:
0.43.10-next.19+1e86a933
this part of the code looks the same:
Copy code
if (customConfig && customConfig.plugins) {
      customConfig.plugins = path.join(appPath, customConfig.plugins);
      if (!fs.existsSync(customConfig.plugins)) {
        throw new Error(
          `Cannot find the esbuild config file at "${customConfig.plugins}"`
        );
      }
    }
f
Hey @Tyler Flint
It looks like it’s pulling that from the 
sst.json
 configuration, and not the function definition
Is
esbuildConfig
set both in the
sst.json
and the Functions’s props?
t
yes it is currently. There was a reason but I don’t recall atm. Let me try to set it in just the
sst.json
and see if that works…
ok so it appears that setting that on the function definition doesn’t have any effect
it’s using the configuration from
sst.json
which is fine with me, I just need to figure out how to not have that configuration mutated on every function build
let me fix it real quick and send a PR…
ok got it
@thdxr looks like what you were working on was most of the way there already. Do you want me to submit a PR or just show you the one line I changed and you can update yours?
t
A PR would be great
t
Got it, thought the appEsbuildConfig was a string
I'll merge this and get the fix out. Overall we need to refactor this code so we're not mutating things and don't need a deep clone
t
cool. Thank you!
it does look like there is a regression case for when the esbuildconfig was a string. If this is prevalent you may need to move the regression case above the clone instead of below.
t
Cloning a string with that code shouldn't break anything anyway
t
perfect
f
As a side note, what do u guys think if we deprecate the
esbuildConfig
setting in
sst.json
.
esbuildConfig
used to only take a string, but now it’s getting more complex with
keepNames
,
define
, and more to come. Maybe we should only allow defining it in FunctionProps?
t
I agree
f
Just a headsup, removed
esbuildConfig
in
sst.json
from the Doc.