question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unexpected token error when deploying with @sls-next/serverless-component@3.5.2

See original GitHub issue

Issue Summary

We have been successfully deploying with serverless-nextjs for a while now. Today we started to experience issues using serverless-component@3.5.2. We let sls-next/serverless-component use latest. The last successful deploy ran at Oct 27, 2021 at 4:14 pm PST. We have not changed the infrastructure, CICD or serverless configuration.

Actual behavior

serverless command fails at a js error from .serverless/components/registry/npm/@sls-next/serverless-component@3.5.2/node_modules/@sls-next/domain/utils.js:505

  error:
  /home/runner/.serverless/components/registry/npm/@sls-next/serverless-component@3.5.2/node_modules/@sls-next/domain/utils.js:505
  const isVersionValid = minimumProtocolVersion.match(validMinimumProtocolVersions)?.length === 1

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/runner/.serverless/components/registry/npm/@sls-next/serverless-component@3.5.2/node_modules/@sls-next/domain/serverless.js:15:5)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

Expected behavior

serverless command successfully deploys the nextjs site to our AWS account.

Steps to reproduce

A copy of the serverless.yml is included with sensitive info redacted:

name: MySite-dev

MySite-dev:
  component: "@sls-next/serverless-component" 
  inputs:
    domain: ['dev', 'example.com']
    certificateArn: "arn:aws:acm:us-east-1:xxx:certificate/xxxx"
    publicDirectoryCache: false
    bucketName: mysite-dev
    name:
      defaultLambda: mysite-dev-lambda
      apiLambda: mysite-dev-apilambda
      imageLambda: mysite-dev-imagelambda

Screenshots/Code/Configuration/Logs

Here is the output when it fails:

  DEBUG ─ Creating invalidations on E1ZMH04ZRANWXX.

  error:
  /home/runner/.serverless/components/registry/npm/@sls-next/serverless-component@3.5.2/node_modules/@sls-next/domain/utils.js:505
  const isVersionValid = minimumProtocolVersion.match(validMinimumProtocolVersions)?.length === 1
                                                                                    ^

SyntaxError: Unexpected token '.'
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/runner/.serverless/components/registry/npm/@sls-next/serverless-component@3.5.2/node_modules/@sls-next/domain/serverless.js:15:5)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at NextjsComponent.load (/home/runner/.serverless/components/registry/npm/@sls-next/serverless-component@3.5.2/node_modules/@serverless/core/src/Component.js:108:24)

Previously there were no errors. Invalidation is successful according to CloudFront.

Versions

Additional context

We run yarn install and npm install serverless -g before syncing down the .serverless state file from s3 and running the serverless command to deploy.

          npm install serverless -g
          yarn install --frozen-lockfile

Checklist

  • You have reviewed the README and FAQs, which answers several common questions.
  • You have reviewed our DEBUGGING wiki and have tried your best to include complete information and reproduction steps (including your configuration) as is possible.
  • You have first tried using the most recent latest or alpha @sls-next/serverless-component release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the old serverless-next.js component and the serverless-next.js plugin are deprecated and no longer maintained.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
seanmccartneysynctreecommented, Oct 29, 2021

Thanks @dphang 💃 I should have included we had been trying Node 12, 14, and 16 with latest sls-next with no luck.

Using Node 14 and 3.5.3-alpha.1 has resolved our issue. I’m guessing we will need to update our serverless.yml when a new version is released.

0reactions
dphangcommented, Oct 29, 2021

Yea, not sure why as Node14 should work with optional chaining…but with the proper transpiling to ES2019 issues like this should hopefully be avoidable in the future.

Ideally you should pin to a specific version instead of latest since while I do try to have good test coverage, occasionally there may be some issues…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unexpected token error on Serverless quick start setup
I am following the docs at this link: https://www.serverless.com/framework/docs/providers/aws/guide/quick-start/#deploy-the-service Have ...
Read more >
Error while deploying NextJS on AWS for serverless framework
When I tried to deploy my NextJS app to AWS with serverless framework. In my next JS app directory, I ran the command...
Read more >
next auth not working in production - You.com | The AI Search ...
In development everything works fine when I log in the session is well created and a JWT token is well generated. On the...
Read more >
Using and Managing vRealize Automation Cloud Assembly
This tutorial guides you as you configure each required component. ... test does not mean that you can deploy the template without errors....
Read more >
Jspdf autotable draw cell example excel file free - Weebly
react-hook-form file validation get size of json object unexpected token react ... error ndc-dynamic how to bind the @INPUT IN the chaild components...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found