milliHQ / terraform-aws-next-js

Terraform module for building and deploying Next.js apps to AWS. Supports SSR (Lambda), Static (S3) and API (Lambda) pages.
https://registry.terraform.io/modules/milliHQ/next-js/aws
Apache License 2.0
1.47k stars 151 forks source link

[Bug] Error while using middleware from Next 12.2 #367

Open MastalerzKamil opened 2 years ago

MastalerzKamil commented 2 years ago

Does the tf-next 1.0.0 canary5 supports middleware from Next 12.2? It has been changed because from developer perspective, now we are using file middleware.ts at the root of the app instead _middleware.ts in pages.

After my investigation I noticed that tf-next 1.0.0 canary 5 has a trouble it while using command tf-next build. The error that appears is the following.

info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
info  - Linting and checking validity of types  
info  - Disabled SWC as replacement for Babel because of custom Babel configuration ".babelrc" https://nextjs.org/docs/messages/swc-disabled
info  - Using external babel configuration from /private/var/folders/ky/64jxxk4n7k1bmhzcbz0zn2740000gn/T/tmp-15280-zg5kTWAsNr1g/.babelrc
info  - Creating an optimized production build  
info  - Compiled successfully
info  - Collecting page data  
info  - Generating static pages (13/13)
info  - Finalizing page optimization  

> Build error occurred
[Error: ENOENT: no such file or directory, open '/private/var/folders/ky/64jxxk4n7k1bmhzcbz0zn2740000gn/T/tmp-11918-8LTrk8VsTpg2/.next/server/edge-runtime-webpack.js'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/private/var/folders/ky/64jxxk4n7k1bmhzcbz0zn2740000gn/T/tmp-11918-8LTrk8VsTpg2/.next/server/edge-runtime-webpack.js'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Build failed:
NowBuildError: Command "yarn run build" exited with 1
    at ChildProcess.<anonymous> (/Users/kamilmastalerz/.nvm/versions/node/v16.15.1/lib/node_modules/tf-next/node_modules/@vercel/build-utils/dist/index.js:33545:20)
    at ChildProcess.emit (node:events:527:28)
    at ChildProcess.emit (node:domain:475:12)
    at maybeClose (node:internal/child_process:1092:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5) {
  hideStackTrace: true,
  code: 'BUILD_UTILS_SPAWN_1',
  link: undefined,
  action: undefined
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I have used before yarn build and everything is fine. Does anyone has a tips how to workaround it. Please fix it because it seems to be an issue on library site

datagutt commented 2 years ago

Middleware is not supported with Lambda and Lambda@Edge, as mentioned both in the top of README and in this issue: https://github.com/milliHQ/terraform-aws-next-js/issues/273#issuecomment-1021486976 I would love for middleware support myself, but this seems to be a limitation with AWS, according to both the author of this projects and other projects (serverless-nextjs).

This, coupled with lack of support for redirects in getServerSideProps, means i am currently unable to use this project for any real-world usage.