next.js AWS放大-未找到模块:错误:无法解析'bufferutil'

brccelvz  于 2023-01-05  发布在  其他
关注(0)|答案(2)|浏览(161)

我在AWS Amplify上部署Next.js应用程序时遇到问题。在“开始SRR构建...”时构建时,它抛出以下内容:

2022-03-18T21:40:34.115Z [INFO]: Starting SSR Build...
2022-03-18T21:43:42.138Z [ERROR]: Error: Command failed with exit code 1: node_modules/.bin/next build
Failed to compile.
ModuleNotFoundError: Module not found: Error: Can't resolve 'bufferutil' in '/codebuild/output/src274598471/src/proj/node_modules/ws/lib'
> Build error occurred
Error: > Build failed because of webpack errors
at /codebuild/output/src274598471/src/proj/node_modules/next/dist/build/index.js:15:924
at async Span.traceAsyncFn (/codebuild/output/src274598471/src/proj/node_modules/next/dist/telemetry/trace/trace.js:6:584)
info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
info  - Checking validity of types...
info  - Creating an optimized production build...
at makeError (/root/.//node_modules/execa/lib/error.js:60:11)
at handlePromise (/root/.//node_modules/execa/index.js:118:26)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async Builder.build (/root/.//node_modules/@sls-next/lambda-at-edge/dist/build.js:377:13)
at async NextjsComponent.build (/root/.//node_modules/@sls-next/-component/dist/component.js:165:13)
at async NextjsComponent.default (/root/.//node_modules/@sls-next/-component/dist/component.js:22:13)
at async fn (/root/.npm/_npx/1924/lib/node_modules//node_modules/@/template/utils.js:280:41)
at async Promise.all (index 0)
at async executeGraph (/root/.npm/_npx/1924/lib/node_modules//node_modules/@/template/utils.js:294:3)
at async Template.default (/root/.npm/_npx/1924/lib/node_modules//node_modules/@/template/.js:67:38)
at async Object.runComponents (/root/.npm/_npx/1924/lib/node_modules//node_modules/@/cli/src/index.js:222:17) {
shortMessage: 'Command failed with exit code 1: node_modules/.bin/next build',
command: 'node_modules/.bin/next build',
escapedCommand: '"node_modules/.bin/next" build',
exitCode: 1,
signal: undefined,
signalDescription: undefined,
stdout: 'info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5\n' +
'info  - Checking validity of types...\n' +
'info  - Creating an optimized production build...',
stderr: 'Failed to compile.\n' +
'\n' +
"ModuleNotFoundError: Module not found: Error: Can't resolve 'bufferutil' in '/codebuild/output/src274598471/src/proj/node_modules/ws/lib'\n" +
'\n' +
'\n' +
'> Build error occurred\n' +
'Error: > Build failed because of webpack errors\n' +
'    at /codebuild/output/src274598471/src/proj/node_modules/next/dist/build/index.js:15:924\n' +
'    at async Span.traceAsyncFn (/codebuild/output/src274598471/src/proj/node_modules/next/dist/telemetry/trace/trace.js:6:584)',
failed: true,
timedOut: false,
isCanceled: false,
killed: false
}

在互联网上的某个地方,我发现对一些人来说,向next.config.js添加外部元素是有效的,但对我来说,它没有。
我的下一个.config.js:

const { i18n } = require('./next-i18next.config');
const path = require('path')

module.exports = {
  reactStrictMode: true,
  i18n,
  eslint: {
    // Warning: This allows production builds to successfully complete even if
    // your project has ESLint errors.
    ignoreDuringBuilds: true,
  },
  externals: [/node-modules/, 'bufferutil', 'utf-8-validate']
}

我将感激任何帮助。

nmpmafwu

nmpmafwu1#

尝试在Amplify控制台应用程序的环境变量部分将以下环境变量设置为true:
第一个月

tzxcd3kk

tzxcd3kk2#

//在webpack.config.js中添加以下属性

externals: {
      bufferutil: "bufferutil",
      "utf-8-validate": "utf-8-validate",
    }

相关问题