I'm having troubles deploying my SST app on SEED.....
# sst
d
I'm having troubles deploying my SST app on SEED... Locally it builds and deploy successfully on Seed I get this generic error:
Copy code
Building Next.js site frontend
Error: There was a problem building the "site" NextjsSite.
    at NextjsSite.buildApp (/tmp/seed/source/node_modules/@serverless-stack/resources/src/NextjsSite.ts:607:13)
    at new NextjsSite (/tmp/seed/source/node_modules/@serverless-stack/resources/src/NextjsSite.ts:148:16)
    at new MainStack (/tmp/seed/source/stacks/MainStack.ts:21:18)
    at Object.main (/tmp/seed/source/stacks/index.ts:5:3)
    at Object.<anonymous> (/tmp/seed/source/.build/run.js:94:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
Error: Subprocess exited with error 1
    at ChildProcess.<anonymous> (/tmp/seed/source/node_modules/aws-cdk/lib/api/cxapp/exec.ts:127:23)
    at ChildProcess.emit (events.js:315:20)
    at ChildProcess.EventEmitter.emit (domain.js:467:12)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
There was an error synthesizing your app.
Any idea how to debug what is going on?
d
Do you pass linting? I’ve had a few times where an error appeared further down from where I actually failed the linting step
d
let me double check but I think I do pass linting
no problems with linting... but comparing local log against Seed log I noticed Seed is using another region
I fixed that but it was not related to the problem
d
Sorry Davide. That was my best guess.
d
👍
d
Can you build the next js site locally?
d
Yep I can also deploy it if I run it locally
I mean the sst deploy command
I guess is something with NextJS build command on Seed / AWS EC2
f
Hey @Davide Ungari, can you try running
sst build
command locally and see if it work?
d
do you have an
.env
file locally that the CI/CD doesnt?
d
@Frank it is building locally and I can also deploy from my machine
Found out the issue... obviously was the stupidest thing ever... for some reason one file is ignored by git
not sure why... anyway I noticed only making a clean clone of the repo 🤦‍♂️
so much wasted time... I still believe would help more details in logging: https://github.com/serverless-stack/serverless-stack/blob/master/packages/resources/src/NextjsSite.ts#L608
what do you think?
j
hi @Davide Ungari, I'm running into the exact same error as you. I'm able to build and deploy locally (using sst build & sst deploy) but when I try to deploy via CI/CD in Seed, it fails when trying to build the NextjsSite. Which file was git ignoring for you? i'm having trouble debugging this so I'm hoping your fix might also work for me. Thanks!
d
knowing the CDK's gitignore, its likely a
.js
file amongst the TS ones.
d
@Jonathan Farmand I have the external .gitignore ( external to the NextJS folder ) that has been auto-generated by the SST script and had a section:
Copy code
# typescript
*.js
*.d.ts
I'm using typescript, not sure why it needs to ignore those files
j
Thanks @Davide Ungari. my external .gitignore doesn’t have those lines in it so it’s likely a different issue. I’ll keep digging.
j
I’m using javascript, sorry forgot to mention that
d
👍
I did a PR that could avoid the issue:
@Jonathan Farmand did you take a look into linting? That is also something that could cause NextJS build failure
j
Yeah I did. That was the first thing I checked based on earlier comments in this thread. I even cleaned up lint warnings.
here’s the error. not sure if the dotenv debug statements are relevant here but i’m using env variables in my sst stack to pass to my nextjs app (i think that’s what this is referring to)
Copy code
[dotenv][DEBUG] did not match key and value when parsing line 1: # These variables are only available in your SST code.
[dotenv][DEBUG] did not match key and value when parsing line 2: # To apply them to your Lambda functions, checkout this doc - <https://docs.serverless-stack.com/environment-variables#environment-variables-in-lambda-functions>
[dotenv][DEBUG] did not match key and value when parsing line 3: 
Building Next.js site frontend
Error: There was a problem building the "Site" NextjsSite.
    at NextjsSite.buildApp (/tmp/seed/source/node_modules/@serverless-stack/resources/src/NextjsSite.ts:607:13)
    at new NextjsSite (/tmp/seed/source/node_modules/@serverless-stack/resources/src/NextjsSite.ts:148:16)
    at new FrontendStack (/tmp/seed/source/stacks/FrontendStack.js:9:18)
    at Object.main (/tmp/seed/source/stacks/index.js:17:3)
    at Object.<anonymous> (/tmp/seed/source/.build/run.js:94:16)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
Error: Subprocess exited with error 1
    at ChildProcess.<anonymous> (/tmp/seed/source/node_modules/aws-cdk/lib/api/cxapp/exec.ts:127:23)
    at ChildProcess.emit (events.js:315:20)
    at ChildProcess.EventEmitter.emit (domain.js:467:12)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
There was an error synthesizing your app.
ERROR: Error: Subprocess exited with error 1
d
I noticed this... if I do a clean checkout and run:
Copy code
npm install
npx sst build --stage develop --region eu-west-1 --verbose
from the root I can reproduce the error
but if I go into the
frontend
folder and do an
npm install
then it works
I then added a console log into the NextjsSite.buildApp... got this:
Copy code
Error: Command failed: node /home/davideu/Workspace/3prawns/webapp/node_modules/@serverless-stack/resources/assets/NextjsSite/build.js --path /home/davideu/Workspace/3prawns/webapp/frontend --output /home/davideu/Workspace/3prawns/webapp/.build/frontend-1640736230330 --config eyJjd2QiOiIvaG9tZS9kYXZpZGV1L1dvcmtzcGFjZS8zcHJhd25zL3dlYmFwcC9mcm9udGVuZCIsImFyZ3MiOlsiYnVpbGQiXX0=
    at checkExecSyncError (child_process.js:643:11)
    at execSync (child_process.js:679:15)
    at NextjsSite.buildApp (/home/davideu/Workspace/3prawns/webapp/node_modules/@serverless-stack/resources/src/NextjsSite.ts:598:15)
    at new NextjsSite (/home/davideu/Workspace/3prawns/webapp/node_modules/@serverless-stack/resources/src/NextjsSite.ts:148:16)
    at new MainStack (/home/davideu/Workspace/3prawns/webapp/stacks/MainStack.ts:21:18)
    at Object.main (/home/davideu/Workspace/3prawns/webapp/stacks/index.ts:5:3)
    at Object.<anonymous> (/home/davideu/Workspace/3prawns/webapp/.build/run.js:94:16)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 816609,
  stdout: null,
  stderr: null
}
ok it simply fail because is missing next:
Copy code
Error building site: Error: Command failed with ENOENT: ./node_modules/.bin/next build
spawn ./node_modules/.bin/next ENOENT
j
right, because the npm install command isn’t running in the frontend folder
d
exactly... but I was expecting the
npx sst build
to take care of it... locally was working just because I did it manually or something like that at a certain point.
j
right, same here. my frontend node_modules was already built before the first time i tried to locally sst build and sst deploy the app