简体   繁体   中英

Error while deploying NextJS app to AWS with 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 npx serverless

and got the following error -

$ npx serverless

  error:
  Error: Command failed with ENOENT: node_modules/.bin/next build
spawn node_modules/.bin/next ENOENT
'node_modules\.bin\next' is not recognized as an internal or external command,
operable program or batch file.
    at notFoundError (C:\Users\patel\.serverless\components\registry\npm\@sls-next\serverless-component@1.18.0\node_modules\@sls-next\serverless-component\node_modules\cross-spawn\lib\enoent.js:6:26)
    at verifyENOENT (C:\Users\patel\.serverless\components\registry\npm\@sls-next\serverless-component@1.18.0\node_modules\@sls-next\serverless-component\node_modules\cross-spawn\lib\enoent.js:40:16)
    at ChildProcess.cp.emit (C:\Users\patel\.serverless\components\registry\npm\@sls-next\serverless-component@1.18.0\node_modules\@sls-next\serverless-component\node_modules\cross-spawn\lib\enoent.js:27:25)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn node_modules/.bin/next',
  path: 'node_modules/.bin/next',
  spawnargs: [ 'build' ],
  originalMessage: 'spawn node_modules/.bin/next ENOENT',
  shortMessage: 'Command failed with ENOENT: node_modules/.bin/next build\n' +
    'spawn node_modules/.bin/next ENOENT',
  command: 'node_modules/.bin/next build',
  exitCode: undefined,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: "'node_modules\\.bin\\next' is not recognized as an internal or external command,\r\n" +
    'operable program or batch file.',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}

  3s » myNextApplication » Error: Command failed with ENOENT: node_modules/.bin/next build
spawn node_modules/.bin/next ENOENT
'node_modules\.bin\next' is not recognized as an internal or external command,
operable program or batch file.

I'm using aws configure to set my AWS credentials.

My serverless.yml file is as follow,

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

How should I deploy my app to AWS cloud with a serverless framework?

Thanks.

I had the same issue and the problem is that I have the setup in a monorepo using yarn workspaces and lerna , and next was declared as a shared dependency in the root of the monorepo, and the nextjs app I was trying to deploy didn't have the dependency explicitly in its package.json.

For serverless to run, we need to have this dependency declared there as well.

in my case, I simply included:

"next": "11.1.3-canary.49",

in dependencies and now serverless is capable to run the command as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM