opennextjs / opennextjs-aws

Open-source Next.js adapter for AWS
https://open-next.js.org
MIT License
3.94k stars 119 forks source link

Bundeled server lambda - Unexpected syntax errors #282

Closed simi-obs closed 11 months ago

simi-obs commented 11 months ago

I am trying to deploy freshly created next project (next@13.5.4) using open-next on my own (without SST) using Cloudformation.

To build the project I am using following command: npx --yes open-next@2.2.3 build --dangerously-disable-dynamodb-cache

:heavy_check_mark: The build goes through fine.

:heavy_check_mark: I am able to zip the serverFunction and deploy it using following config:

MyWebServerFunctionFunction:
    Type: AWS::Lambda::Function
    Properties:
      FunctionName: next-test-myWebServerFunction
      Code:
        S3Key: ee53a040691e593de5d4b28b8ba685901070068d.zip
        S3Bucket: stp-deployment-bucket-91f593ef
      Handler: index.handler
      MemorySize: 1024
      Timeout: 30
      Environment:
        Variables:
          CACHE_BUCKET_NAME:
            Ref: MyWebBucketBucket
          CACHE_BUCKET_PREFIX: _cache
          CACHE_BUCKET_REGION: eu-west-1
          REVALIDATION_QUEUE_URL:
            Ref: MyWebRevalidationQueueQueue
          REVALIDATION_QUEUE_REGION: eu-west-1
      Role:
        Fn::GetAtt:
          - MyWebServerFunctionRole
          - Arn
      Runtime: nodejs18.x

:crossed_swords: however upon invocation, the lambda function crashes. After inspecting Cloudwatch logs this is what I found:

2023-10-17T12:38:41.680Z    undefined   ERROR   Uncaught Exception  {
    "errorType": "Runtime.UserCodeSyntaxError",
    "errorMessage": "SyntaxError: Unexpected string",
    "stack": [
        "Runtime.UserCodeSyntaxError: SyntaxError: Unexpected string",
        "    at _loadUserApp (file:///var/runtime/index.mjs:1058:17)",
        "    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1093:21)",
        "    at async start (file:///var/runtime/index.mjs:1256:23)",
        "    at async file:///var/runtime/index.mjs:1262:1"
    ]
}

Interestingly if I change something within my src/app/page.tsx the error varies a bit. I.e I can get

2023-10-17T12:53:30.208Z    undefined   ERROR   Uncaught Exception  {"errorType":"Runtime.UserCodeSyntaxError","errorMessage":"SyntaxError: Unexpected token '}'","stack":["Runtime.UserCodeSyntaxError: SyntaxError: Unexpected token '}'","    at _loadUserApp (file:///var/runtime/index.mjs:1058:17)","    at async UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1093:21)","    at async start (file:///var/runtime/index.mjs:1256:23)","    at async file:///var/runtime/index.mjs:1262:1"]}

It is still a syntax error but somewhat different.

Do you have any idea what the problem might be here?

simi-obs commented 11 months ago

Ok seems like my zip is somehow getting corrupted so this will probably be mistake on my side... closing this one