sladg / nextjs-lambda

Lambda deployments for Nextjs12 & Nextjs13 (standalone). Easy CLI commands to get your standalone Next output to run in AWS Lambda (not @Edge)! Uses CDK in behind and produces code zips importable to Terraform, Serverless, Azure, etc.
MIT License
169 stars 19 forks source link

`config.json` 's body is just `nextConfig`, not valid JSON. #88

Closed schematical closed 1 year ago

schematical commented 1 year ago

So I am getting an error when uploading this to AWS Lambda:

/var/task/config.json: Unexpected token e in JSON at position 1

When you look in the generated config.json the entire body is as follows

nextConfig

so it is NOT valid json.

I did some digging in the code and found this area here where it seems to try and pull the contents of that config.json https://github.com/sladg/nextjs-lambda/blob/1b278aef890e86f17ddf81998913ea88b8391b37/lib/cli/pack.ts#L93 using this regex: https://github.com/sladg/nextjs-lambda/blob/1b278aef890e86f17ddf81998913ea88b8391b37/lib/consts.ts#LL1C14-L1C35

So when I do the same search locally in my generated files I find this bit of code:

  const nextServer = new NextServer({
    hostname,
    port: currentPort,
    dir: path.join(__dirname),
    dev: false,
    customServer: false,
    conf: nextConfig,
  })

Notice the second to last line there. It seems to just be pulling the string nextConfig rather than the value of it.

Here is my package.json

{
  "name": "xyz-www",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@apollo/client": "^3.7.13",
    "@types/node": "18.16.3",
    "@types/react": "18.2.0",
    "@types/react-dom": "18.2.1",
    "autoprefixer": "10.4.14",
    "bootstrap": "^5.3.0-alpha3",
    "eslint": "8.39.0",
    "eslint-config-next": "13.3.4",
    "filerobot-image-editor": "^4.4.0",
    "next": "13.3.4",
    "postcss": "8.4.23",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-filerobot-image-editor": "^4.4.0",
    "tailwindcss": "3.3.2",
    "typescript": "5.0.4"
  },
  "devDependencies": {
  }
}

Any suggestions?

sladg commented 1 year ago

I see, it seems like Next changed code a bit, there used actual configuration (aka. object) in place of nextConfig. For quick-fix, you can downgrade next.js, I will look into it in a meantime.