使用serverless框架将NextJS应用程序部署到AWS时出现错误。

3

当我尝试使用serverless框架将我的NextJS应用程序部署到AWS时。

在我的NextJS应用程序目录中,我运行了命令npx serverless

然后出现了以下错误 -

$ 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.

我正在使用aws configure命令来设置我的AWS凭证。

我的serverless.yml文件如下所示,

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

我应该如何使用无服务器框架将我的应用程序部署到AWS云上?

谢谢。


1
在执行该命令之前,你是否运行了 npm install 命令? - juliomalves
是的,所有需要的模块都已经完美地安装了。 - Tanay
1个回答

0

我遇到了同样的问题,问题在于我使用了 yarn workspaceslerna 在一个 monorepo 中进行设置,并且在 monorepo 的根目录中声明了 next 作为共享依赖项,但我尝试部署的 nextjs 应用程序在其 package.json 文件中没有明确声明该依赖项。

为了使 serverless 运行,我们还需要在其中声明此依赖项。

在我的情况下,我只需包含:

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

在依赖项中,现在无服务器也能够运行该命令。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接