Getting a weird error that I'm not sure how to deb...
# help
b
Getting a weird error that I'm not sure how to debug … Seemingly all of a sudden, when I try to
deploy
an SST API Stack, I'm getting a reported linting error. I can't figure out why it's happening. Have tried rolling back to earlier commits, but still getting the same error. Any pointers greatly appreciated 😅 SST debug log attached, if that helps! BTW, everything works fine if I run locally, using
npx sst start
f
Hey @Brett Gullan, can you try running
sst build
and see if that works for you?
b
Nope,
build
fails …
If I set
"lint": false
in sst.json,
build
works. So definitely looks to be a linting issue.
Any thoughts on how I can more directly access the linting process, to get some better debugging output? For the life of me, I can't find the issue.
f
Can you check if the
.build/eslint.js
exists in your app?
b
Yes, it does. And I’ve been playing around with calling it directly, and it seems to run and exit normally.
I’ve also double-checked that all the files referenced in the sst-debug.log exist.
f
hmm.. can u open up
/Users/brett/Development/scripts-now-monorepo/node_modules/cross-spawn/index.js
and before line 26, print out
console.log(parsed.command, parsed.args, parsed.options);
?
b
Copy code
node [
  '/Users/brett/Development/scripts-now-monorepo/packages/api/.build/eslint.js',
  '--color',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/lib/Network.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/lib/Database.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/lib/ScriptsNowApiStack.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/lib/index.js'
] {
  stdio: 'inherit',
  cwd: '/Users/brett/Development/scripts-now-monorepo/node_modules/@serverless-stack/cli'
}
f
Can u try running this super long command in ur cli?
Copy code
cd /Users/brett/Development/scripts-now-monorepo/node_modules/@serverless-stack/cli && node /Users/brett/Development/scripts-now-monorepo/packages/api/.build/eslint.js --color /Users/brett/Development/scripts-now-monorepo/packages/api/lib/Network.js /Users/brett/Development/scripts-now-monorepo/packages/api/lib/Database.js /Users/brett/Development/scripts-now-monorepo/packages/api/lib/ScriptsNowApiStack.js /Users/brett/Development/scripts-now-monorepo/packages/api/lib/index.js
b
That exits normally.
I've used a similar command, called from within the project
.build
directory, against all the Lambda function code. It also exits normally.
f
hmm.. i wonder if
cp.spawnSync
can’t find the
node
binary or a js file..
Just did some tests.. the error seems to mean it can’t find the
node
binary
b
Okaaay … that’s very weird.
Especially as I’m having the same problem on two different development machines.
f
Did it start happening after any changes? ie. updating SST version; updating Node version; etc?
b
Not that I can recall. However, I have wiped my
node_modules
dirs and reinstalled a couple of times. So whatever has happened must have snuck in then.
f
hey Brett, when you logged
console.log(parsed.command, parsed.args, parsed.options);
, it should get printed out twice
first time for linting the SST code, 2nd time for linting the Lambda code
the error comes from when linting the Lambda code
and the output u sent above was for linting the SST code
can u send me the output for linting the Lambda code?
b
Copy code
node [
  '/Users/brett/Development/scripts-now-monorepo/packages/api/.build/eslint.js',
  '--color',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/src/functions/configuration.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/src/functions/template.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/src/database/models/MedicationsCategory.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/src/database/models/Medication.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/src/database/services/transformations.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/src/database/services/medication-catalogue.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/src/database/index.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/src/functions/medications.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/src/functions/medications-{brandname}.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/src/functions/medications-{brandname}-substitutes.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/src/functions/medications-category-{category}.js',
  '/Users/brett/Development/scripts-now-monorepo/packages/api/src/functions/medications-categories.js'
] {
  stdio: 'inherit',
  cwd: '/Users/brett/Development/scripts-now-monorepo/packages/api/node_modules/@serverless-stack/cli'
}
f
can you do
cd /Users/brett/Development/scripts-now-monorepo/packages/api/node_modules/@serverless-stack/cli
and see if the path exists?
b
No,
/Users/brett/Development/scripts-now-monorepo/packages/api/node_modules/@serverless-stack/cli
doesn't exist there. The CLI package is installed at the monorepo root level.
/Users/brett/Development/scripts-now-monorepo/node_modules/@serverless-stack/cli
Ok. So definitely an issue with the monorepo. Using
npm i
within the affected package (
./packages/api
) and SST build works fine.
Apologies, I missed that.
One of the reasons I have been wiping the
node_modules
dirs, was to try to ensure a clean monorepo install. I had thought I’d deployed previously on that basis. Maybe not.
What is the status of monorepo support with SST?
f
Can you check something quickly.. run
ls -l /Users/brett/Development/scripts-now-monorepo/packages/api/node_modules/@serverless-stack/
and see what’s in there?
I’m guessing that you have
@serverless-stack/cli
inside root’s node_modules; and
@serverless-stack/resources
inside a subdirectory’s node_modules
b
Yup. I've got
core
and
resources
inside the package's node_modules.
And …
cli
,
core
and
resources
at root level.
f
hmm.. any reason why
cli
is at the root? Do u have multiple SST apps in the same repo?
We create a recommended monorepo setup with Lerna and Yarn workspaces - https://github.com/serverless-stack/lerna-yarn-starter
b
Ah … yes. I’ve got an API stack and a StaticSite stack, each in separate packages.
f
Ah I see.. if you adopt the starter, you would have just 1 SST app with API and StaticSite stacks.
But if you want to keep ur setup (multiple SST apps), you just have to ensure either
cli
core
and
resources
are all hoisted at the root. Or they are all present in both apps.
b
I’ll have a look at the starter. But thinking I might need to maintain my current setup. Anyway, at least I know what I’m dealing with now. Absolutely would not have figured that out on my own! So thank you for the help. Really appreciated. 🙏
f
No worries! Just opened an issue to track what we’ve talked about https://github.com/serverless-stack/serverless-stack/issues/514