Serverless-next.js: Started getting the Error: Cannot find module '@sls-next/next-aws-cloudfront'

Created on 1 Jul 2020  ·  17Comments  ·  Source: serverless-nextjs/serverless-next.js

Describe the bug
My deployments have been working well on AWS being ran by code build. Today I suddenly got an error for my builds on two separate AWS instances with the error:

{ Error: Cannot find module '@sls-next/next-aws-cloudfront'
--
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
at Function.resolve (internal/modules/cjs/helpers.js:33:19)
at Builder.<anonymous> (/root/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/build.js:119:49)
at Generator.next (<anonymous>)
at /root/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/build.js:8:71
at new Promise (<anonymous>)
at __awaiter (/root/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/build.js:4:12)
at Builder.buildDefaultLambda (/root/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/build.js:98:16)
at Builder.<anonymous> (/root/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/build.js:266:24)
at Generator.next (<anonymous>) code: 'MODULE_NOT_FOUND' }
·[G·[?25h·[G·[J
64s › myApp › Error: Cannot find module '@sls-next/next-aws-cloudfront'

Expected behaviour
Ideally the deployment should give a success and output the cloudfront link.

Additional context
I haven't had any package related issue with the package and I'm running using the following in my package JSON.

    "serverless": "^1.67.0",
    "serverless-next.js": "^1.9.5",
triage

Most helpful comment

Hi folks, please pin the version number in your serverless.yml like it states in the README. For example:

myNextApplication:
  component: "[email protected]"

All 17 comments

I've started experiencing this issue in my CI in the last 2 days.

I've started experiencing this issue in my CI in the last 2 days.

Could be tied to a commit made on their package.json. I saw that an update was made 19 hours ago.

Hi folks, please pin the version number in your serverless.yml like it states in the README. For example:

myNextApplication:
  component: "[email protected]"

Thanks it works.

Must be a new config from when I plugged in the package into my project. I followed the docs when they were at this state: https://github.com/serverless-nextjs/serverless-next.js/blob/ed2b3beda852a3ed55789d167cb378cdbe690d53/README.md. Haven't had a need to look at them since then.

GitHub
⚡ Deploy your next apps using the serverless framework - serverless-nextjs/serverless-next.js

Same for me, I have had it without the version based on those docs.

Pinning the version has resolved for me. Thanks!

Thanks it works.

Must be a new config from when I plugged in the package into my project. I followed the docs when they were at this state: https://github.com/serverless-nextjs/serverless-next.js/blob/ed2b3beda852a3ed55789d167cb378cdbe690d53/README.md. Haven't had a need to look at them since then.

Yeah that changed a while back and is now via the serverless.yml how you pin a version number. Also just for visibility to people landing into this issue, I've renamed the package to @sls-next/serverless-component to keep everything under @sls-next but that's till on alpha. Once it makes it to stable I'll deprecate the serverless-next.js npm package.

GitHub
⚡ Deploy your next apps using the serverless framework - serverless-nextjs/serverless-next.js

I don't know what to put in my serverless.yml. All I have is component: serverless-next.js under myApp, and I don't seem to have a serverless-next package installed. Also, the instructions on serverless.com say this:

# serverless.yml
myApp:
 component: serverless-next.js

How do I find the version of serverless-next that I should pin it to in my serverless.yml?

It seems like to resolve this issue we have to go to at least 1.14.0 ...

Which at that version I can't get the names of the lambdas to be set correctly as it looks like that pull request was in 1.15.0-alpha.0

Am I correct in these assumptions? Any idea if there can be a 1.14.1 release with the name fix or any idea when the cloudfront package issue in the 1.15.0-alpha series will be resolved?

Thanks!

it worked for me by replacing

# serverless.yml
myApp:
 component: serverless-next.js

to

# serverless.yml
myApp:
 component: "[email protected]"

it worked for me by replacing

# serverless.yml
myApp:
 component: serverless-next.js

to

# serverless.yml
myApp:
 component: "[email protected]"

Just be aware 1.9.5 is 5 minor versions behind... Suggest using 1.14.0 or 1.15.0-alpha.1(last known good before breaking changes)

Would it make sense by default to use the version installed locally?

it worked for me by replacing

# serverless.yml
myApp:
 component: serverless-next.js

to

# serverless.yml
myApp:
 component: "[email protected]"

Just be aware 1.9.5 is 5 minor versions behind... Suggest using 1.14.0 or 1.15.0-alpha.1(last known good before breaking changes)

What if I have "serverless-next.js": "^1.7.0" in package.json
but
"serverless-next.js": {
"version": "1.11.2",
...
in package-lock.json? What version is better to pin there?

1.14.0 works okay on macos but not on amazon linux 2 running on docker. So in order to let my jenkins handle deployments to aws, I had to downgrade to 1.9.5 for the time being.

I hope a fixed version will be released soon.

@stary71 Version pinning doesn't work through package.json. Make sure you use the serverless.yml for that as I suggested in my comment.

@zoozalp Can you try @sls-next/[email protected] ?

@stary71 Version pinning doesn't work through package.json. Make sure you use the serverless.yml for that as I suggested in my comment.

@zoozalp Can you try @sls-next/[email protected] ?

I was using serverless.yml as suggested in previous replies, not package.json file.

Pinning [email protected] gives me error -> Error: Component "serverless-next.[email protected]" was not found on NPM nor could it be resolved locally.

However pinning @sls-next/[email protected] gives me another error -> InvalidParameterValueException: Lambda was unable to delete arn:aws:lambda:us-east-1:314787751538:function:nl5x8zc-q9zxla:20 because it is a replicated function. Please see our documentation for Deleting Lambda@Edge Functions and Replicas.

I guess I'll need to delete existing lamda edge function before I try again. It's going to take at least an hour before aws lets me delete the edge lambdas. I'll let you know as soon as I can.

Thank you @danielcondemarin , it worked nicely after deleting existing cloudfront distribution and lambdas.

# serverless.yml
myApp:
 component: "@sls-next/[email protected]"

and my lambdas are named properly now. 🎉🎉🎉

Hi,
is there any way of not deleting the existing stack, and solving this issue?
I've just cloned my repo from a new machine and tried to deploy locally and it failed. (same serverless version and node version)

nextApp:
  component: "[email protected]"

Here is the stack trace:

npx serverless

  error:
  Error: Cannot find module '@sls-next/next-aws-cloudfront'
Require stack:
- /Users/****/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/build.js
- /Users/****/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/index.js
- /Users/****/.serverless/components/registry/npm/[email protected]/node_modules/serverless-next.js/serverless.js
- /Users/****/.nvm/versions/node/v12.14.1/lib/node_modules/serverless/node_modules/@serverless/core/src/Component.js
- /Users/****/.nvm/versions/node/v12.14.1/lib/node_modules/serverless/node_modules/@serverless/core/src/index.js
- /Users/****/.nvm/versions/node/v12.14.1/lib/node_modules/serverless/node_modules/@serverless/cli/src/index.js
- /Users/****/.nvm/versions/node/v12.14.1/lib/node_modules/serverless/bin/serverless.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:793:17)
    at Function.resolve (internal/modules/cjs/helpers.js:80:19)
    at Builder.<anonymous> (/Users/****/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/build.js:119:49)
    at Generator.next (<anonymous>)
    at /Users/****/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/build.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/Users/****/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/build.js:4:12)
    at Builder.buildDefaultLambda (/Users/****/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/build.js:98:16)
    at Builder.<anonymous> (/Users/****/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/build.js:266:24)
    at Generator.next (<anonymous>) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/****/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/build.js',
    '/Users/****/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/index.js',
    '/Users/****/.serverless/components/registry/npm/[email protected]/node_modules/serverless-next.js/serverless.js',
    '/Users/****/.nvm/versions/node/v12.14.1/lib/node_modules/serverless/node_modules/@serverless/core/src/Component.js',
    '/Users/****/.nvm/versions/node/v12.14.1/lib/node_modules/serverless/node_modules/@serverless/core/src/index.js',
    '/Users/****/.nvm/versions/node/v12.14.1/lib/node_modules/serverless/node_modules/@serverless/cli/src/index.js',
    '/Users/****/.nvm/versions/node/v12.14.1/lib/node_modules/serverless/bin/serverless.js'
  ]
}

  23s › database › Error: Cannot find module '@sls-next/next-aws-cloudfront'
Require stack:
- /Users/****/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/build.js
- /Users/****/.serverless/components/registry/npm/[email protected]/node_modules/@sls-next/lambda-at-edge/dist/index.js
- /Users/****/.serverless/components/registry/npm/[email protected]/node_modules/serverless-next.js/serverless.js
- /Users/****/.nvm/versions/node/v12.14.1/lib/node_modules/serverless/node_modules/@serverless/core/src/Component.js
- /Users/****/.nvm/versions/node/v12.14.1/lib/node_modules/serverless/node_modules/@serverless/core/src/index.js
- /Users/****/.nvm/versions/node/v12.14.1/lib/node_modules/serverless/node_modules/@serverless/cli/src/index.js
- /Users/****/.nvm/versions/node/v12.14.1/lib/node_modules/serverless/bin/serverless.js

One thing that does worry me a bit is that it's trying to access my global npm modules and searching there instead of using the local npm modules in the repository.

Any ideas on how to solve this?

Was this page helpful?
0 / 5 - 0 ratings