serverless-nextjs / serverless-next.js

⚡ Deploy your Next.js apps on AWS Lambda@Edge via Serverless Components
MIT License
4.47k stars 457 forks source link

Cannot find module '@sls-next/next-aws-cloudfront' with serverless-next.js@1.14.0 #504

Closed jfacchini closed 4 years ago

jfacchini commented 4 years ago

Describe the bug Since this morning, we're not able to deploy our application due to a missing module Cannot find module '@sls-next/next-aws-cloudfront'

We've faced this problem in the past and fixed like described here: https://github.com/serverless-nextjs/serverless-next.js/issues/480#issuecomment-652450945 This has worked for some time but today we're back to the same issue.

As I understand there is another package available prefixed with @sls-next : https://github.com/serverless-nextjs/serverless-next.js/issues/480#issuecomment-657196903 but this is only from version 1.15.x as I understand but we're currently using 1.14.0

To Reproduce Here is the serverless.yml configuration that we're using:

site:
  component: serverless-next.js@1.14.0
  inputs:
    # environment variable syntax is coming from serverless components v1.x
    # see the correct documentation here: https://github.com/serverless/components/tree/v1#environment-variables
    bucketName: ${env.DEPLOYMENT_BUCKET}
    AccelerateConfiguration:
      AccelerationStatus: Enabled

Screenshots

aNA
  39s › site › Deploying 
aNA
  error:
  Error: Cannot find module '@sls-next/next-aws-cloudfront'
Require stack:
- /root/.serverless/components/registry/npm/serverless-next.js@1.14.0/node_modules/@sls-next/lambda-at-edge/dist/build.js
- /root/.serverless/components/registry/npm/serverless-next.js@1.14.0/node_modules/@sls-next/lambda-at-edge/dist/index.js
- /root/.serverless/components/registry/npm/serverless-next.js@1.14.0/node_modules/serverless-next.js/serverless.js
- /usr/src/app/node_modules/@serverless/core/src/Component.js
- /usr/src/app/node_modules/@serverless/core/src/index.js
- /usr/src/app/node_modules/@serverless/cli/src/index.js
- /usr/src/app/node_modules/serverless/lib/components-v1.js
- /usr/src/app/node_modules/serverless/bin/serverless.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:966:15)
    at Function.resolve (internal/modules/cjs/helpers.js:78:19)
    at Builder.<anonymous> (/root/.serverless/components/registry/npm/serverless-next.js@1.14.0/node_modules/@sls-next/lambda-at-edge/dist/build.js:119:49)
    at Generator.next (<anonymous>)
    at /root/.serverless/components/registry/npm/serverless-next.js@1.14.0/node_modules/@sls-next/lambda-at-edge/dist/build.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/root/.serverless/components/registry/npm/serverless-next.js@1.14.0/node_modules/@sls-next/lambda-at-edge/dist/build.js:4:12)
    at Builder.buildDefaultLambda (/root/.serverless/components/registry/npm/serverless-next.js@1.14.0/node_modules/@sls-next/lambda-at-edge/dist/build.js:98:16)
    at Builder.<anonymous> (/root/.serverless/components/registry/npm/serverless-next.js@1.14.0/node_modules/@sls-next/lambda-at-edge/dist/build.js:266:24)
    at Generator.next (<anonymous>) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/root/.serverless/components/registry/npm/serverless-next.js@1.14.0/node_modules/@sls-next/lambda-at-edge/dist/build.js',
    '/root/.serverless/components/registry/npm/serverless-next.js@1.14.0/node_modules/@sls-next/lambda-at-edge/dist/index.js',
    '/root/.serverless/components/registry/npm/serverless-next.js@1.14.0/node_modules/serverless-next.js/serverless.js',
    '/usr/src/app/node_modules/@serverless/core/src/Component.js',
    '/usr/src/app/node_modules/@serverless/core/src/index.js',
    '/usr/src/app/node_modules/@serverless/cli/src/index.js',
    '/usr/src/app/node_modules/serverless/lib/components-v1.js',
    '/usr/src/app/node_modules/serverless/bin/serverless.js'
  ]
}
thomaswienecke commented 4 years ago

We are having the same issue on version 1.12.0-alpha.6 since today.

danielcondemarin commented 4 years ago

Do you have serverless-next.js in your package.json deps? If you do could you remove it and try again?

jfacchini commented 4 years ago

Hi @danielcondemarin, thanks for your quick reply.

Effectively we had serverless-next.js as a dependency in package.json. Unfortunately, removing the dependency is still giving me the same error.

thomaswienecke commented 4 years ago

Sadly, removing it doesn't work for us either.

danielcondemarin commented 4 years ago

Although I'll try to get to the bottom of the problem please try updating to the latest stable published:

myNextApplication:
  component: "@sls-next/serverless-component@1.15.1"
  ...

There shouldn't be breaking changes.

katspaugh commented 4 years ago

I'm also having this, and pinning to 1.15.1 unfortunately didn't help.

danielcondemarin commented 4 years ago

I'm also having this, and pinning to 1.15.1 unfortunately didn't help.

I've just tested and using,

myNextApplication:
  component: "@sls-next/serverless-component@1.15.1"

works fine for me. Note the package name change now under an org @sls-next/

jfacchini commented 4 years ago

Thanks @danielcondemarin this is effectively working for us with 1.15.1 and as far as we're not yet in production that's easy to change.

Hopefully you'll be able to find out what's the problem for the older versions.

🤞

danielcondemarin commented 4 years ago

Unfortunately there was a breaking change introduced here accidentally. I suspect serverless is picking a version of @sls-next/lambda-at-edge that isn't compatible with the package serverless-next.js. This isn't an issue with @sls-next/serverless-component because its up to date.

Like I said earlier I don't expect any breaking changes when using @sls-next/serverless-component@1.15.1. If anyone comes across this issue please try updating to that. If after updating it doesn't work then feel free to open a new issue 👍

katspaugh commented 4 years ago

Thanks Daniel, it does work with @sls-next/serverless-component@1.15.1. Sorry, I totally missed the name change. Cool that you found the root cause!

Harrisonkamau commented 4 years ago

I'm getting a syntax error: Nextjs - v9.4.4 Node - v8.11.2

Stack trace:

/Users/harrisonkamau/.serverless/components/registry/npm/@sls-next/serverless-component@1.15.1/node_modules/fs-extra/lib/mkdirs/make-dir.js:85
      } catch {
              ^

SyntaxError: Unexpected token {
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:616:28)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/harrisonkamau/.serverless/components/registry/npm/@sls-next/serverless-component@1.15.1/node_modules/fs-extra/lib/mkdirs/index.js:3:44)

Here's my serverless.yml

nextApp:
  component: "@sls-next/serverless-component@1.15.1"

components:
  apiEndpoint:
    type: rest-api
    inputs:
      gateway: aws-apigateway
      routes:
        /execute:
          get:
            function: ${sfmcExecuteFunction}
sfmcExecuteFunction:
  type: aws-lambda
  inputs:
    handler:
      integrations/index.execute
Harrisonkamau commented 4 years ago

I resolved the above error by using version 12.18.2 of Node.js

krish-dev commented 4 years ago

I was using the pinned way of the version of 1.13.0 like this component: serverless-next.js@1.13.0 but encountered the same issue. Currently, I updated it by a new version with a component: "@sls-next/serverless-component@1.15.1" and the issue gets resolved but it requires creating new CloudFront distribution, not work with existing.

I have noticed one thing while I'm dedicatedly used 1.13.0 version of serverless-next.js the internal dependency @sls-next/lambda-at-edge get updated. lambda-at-edge package having breaking changes between 2 version. This is the actual cause of encounter the issue.

"_from": "@sls-next/lambda-at-edge@^1.3.0",
"_id": "@sls-next/lambda-at-edge@1.5.1",

Screenshot 2020-07-16 at 1 04 41 PM

@danielcondemarin do you have any plan for overcoming this kind backward compatibility issue that the previous version of the component will have fixed version of internal dependency to avoid this kind issue and Community get a pace to migared to the new version. Currently, they are forced to migrate to the new one.

danielcondemarin commented 4 years ago

I was using the pinned way of the version of 1.13.0 like this component: serverless-next.js@1.13.0 but encountered the same issue. Currently, I updated it by a new version with a component: "@sls-next/serverless-component@1.15.1" and the issue gets resolved but it requires creating new CloudFront distribution, not work with existing.

I have noticed one thing while I'm dedicatedly used 1.13.0 version of serverless-next.js the internal dependency @sls-next/lambda-at-edge get updated. lambda-at-edge package having breaking changes between 2 version. This is the actual cause of encounter the issue.

"_from": "@sls-next/lambda-at-edge@^1.3.0",
"_id": "@sls-next/lambda-at-edge@1.5.1",

Screenshot 2020-07-16 at 1 04 41 PM

@danielcondemarin do you have any plan for overcoming this kind backward compatibility issue that the previous version of the component will have fixed version of internal dependency to avoid this kind issue and Community get a pace to migared to the new version. Currently, they are forced to migrate to the new one.

Do you know what's causing it to create a new distribution? I didn't expect that happening. I think we should fix that.

krish-dev commented 4 years ago

Do you know what's causing it to create a new distribution? I didn't expect that happening. I think we should fix that.

Yes, I can share the failed log with you. Maybe you can understand the cause of it.

Here is my configuration

myapp:
    component: "@sls-next/serverless-component@1.15.1"
    inputs:
        name: ${env.BUILD_INSTANCE}
        memory: 512
        bucketName: ${env.BUILD_INSTANCE}
        useServerlessTraceTarget: true

Here is the log

error:
  { InvalidParameterValueException: Lambda was unable to delete arn:aws:lambda:us-east-1:005818240226:function:qq0zb3-7y170vb:102 because it is a replicated function. Please see our documentation for Deleting Lambda@Edge Functions and Replicas.
    at Object.extractError (/root/.serverless/components/registry/npm/@sls-next/serverless-component@1.15.1/node_modules/aws-sdk/lib/protocol/json.js:51:27)
    at Request.extractError (/root/.serverless/components/registry/npm/@sls-next/serverless-component@1.15.1/node_modules/aws-sdk/lib/protocol/rest_json.js:55:8)
    at Request.callListeners (/root/.serverless/components/registry/npm/@sls-next/serverless-component@1.15.1/node_modules/aws-sdk/lib/sequential_executor.js:106:20)
    at Request.emit (/root/.serverless/components/registry/npm/@sls-next/serverless-component@1.15.1/node_modules/aws-sdk/lib/sequential_executor.js:78:10)
    at Request.emit (/root/.serverless/components/registry/npm/@sls-next/serverless-component@1.15.1/node_modules/aws-sdk/lib/request.js:688:14)
    at Request.transition (/root/.serverless/components/registry/npm/@sls-next/serverless-component@1.15.1/node_modules/aws-sdk/lib/request.js:22:10)
    at AcceptorStateMachine.runTo (/root/.serverless/components/registry/npm/@sls-next/serverless-component@1.15.1/node_modules/aws-sdk/lib/state_machine.js:14:12)
    at /root/.serverless/components/registry/npm/@sls-next/serverless-component@1.15.1/node_modules/aws-sdk/lib/state_machine.js:26:10
    at Request.<anonymous> (/root/.serverless/components/registry/npm/@sls-next/serverless-component@1.15.1/node_modules/aws-sdk/lib/request.js:38:9)
    at Request.<anonymous> (/root/.serverless/components/registry/npm/@sls-next/serverless-component@1.15.1/node_modules/aws-sdk/lib/request.js:690:12)
  message:
   'Lambda was unable to delete arn:aws:lambda:us-east-1:005818240226:function:qq0zb3-7y170vb:102 because it is a replicated function. Please see our documentation for Deleting Lambda@Edge Functions and Replicas.',
  code: 'InvalidParameterValueException',
  time: 2020-07-15T06:29:51.324Z,
  requestId: '04e3d477-719b-4f27-9859-432300efbd5a',
  statusCode: 400,
  retryable: false,
  retryDelay: 89.09598863511351 }

One minor observation, in lambda functions id previously it was random string but now it is the same as inputs:name: Attached the screenshot.

Screenshot 2020-07-16 at 1 49 19 PM

danielcondemarin commented 4 years ago

One minor observation, in lambda functions id previously it was random string but now it is the same as inputs:name: Attached the screenshot.

Good spot. If you take out the name does it work? We fixed a while back the aws-lambda name not being set correctly.

krish-dev commented 4 years ago

Good spot. If you take out the name does it work? We fixed a while back the aws-lambda name not being set correctly.

I have not tried to remove the name as the configuration was the same for while we are using 1.13.0 version.

I will try and let you know.

danielcondemarin commented 4 years ago

I have not tried to remove the name as the configuration was the same for while we are using 1.13.0 version.

I will try and let you know.

I suspect this issue would happen for any users that had set the name input which wasn't actually working before this PR was merged.

Now that it is working, then the aws-lambda component will try deleting the lambdas that were previously created using an autogenerated name and create new ones with the name defined via the input.

That's my theory anyway, let's confirm it first.

krish-dev commented 4 years ago

@danielcondemarin

Yes with @sls-next/serverless-component@1.15.1 and without name it worked.

danielcondemarin commented 4 years ago

@danielcondemarin

Yes with @sls-next/serverless-component@1.15.1 and without name it worked.

That's great news.

For other people landing on this issue, TL;DR is:

hugomn commented 4 years ago

I have the same issue for 1.17.0 when trying to delete, and I cannot use 1.15.1 because it's broken now with the InvalidArgument: The parameter MinTTL is required (https://github.com/serverless-nextjs/serverless-next.js/issues/626). Any version where the issue Cannot find module is fixed newer the 1.16.0?