{"id":14770,"library":"ns-build","title":"Next.js Serverless Build Tool","description":"ns-build is a CLI utility designed to simplify the build process for Next.js applications intended for serverless deployment on AWS using Terraform. It primarily functions as a bash script, automating the steps required to prepare a Next.js project (specifically those configured with `output: 'standalone'`) for deployment. The current stable version is 3.1.1. It maintains a consistent release cadence with updates to support newer Next.js versions (e.g., v15, v16) and Node.js runtimes (e.g., Node 22, Node 24) on AWS Lambda. Its key differentiator is its tight integration with the `nextjs-serverless` Terraform module, providing a streamlined workflow from build to infrastructure deployment without requiring manual asset compilation or environment setup for AWS Lambda and CloudFront distributions.","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/emyriounis/terraform-aws-nextjs-serverless","tags":["javascript"],"install":[{"cmd":"npm install ns-build","lang":"bash","label":"npm"},{"cmd":"yarn add ns-build","lang":"bash","label":"yarn"},{"cmd":"pnpm add ns-build","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required peer dependency for Next.js application compilation, specifying compatible versions.","package":"next","optional":false}],"imports":[],"quickstart":{"code":"{\n  \"name\": \"my-nextjs-app\",\n  \"version\": \"0.1.0\",\n  \"scripts\": {\n    \"build\": \"ns-build build\"\n  },\n  \"dependencies\": {\n    \"next\": \"^16.0.0\",\n    \"react\": \"^18\",\n    \"react-dom\": \"^18\"\n  },\n  \"devDependencies\": {\n    \"ns-build\": \"^3.0.1\"\n  }\n}\n// next.config.js\n/** @type {import('next').NextConfig} */\nconst nextConfig = {\n  output: 'standalone',\n};\nmodule.exports = nextConfig;\n\n// Run the build command\n// npm install\n// npm run build\n\n// The output will be in ./.ns-build and is intended to be used by the\n// 'nextjs-serverless' Terraform module for deployment to AWS.\n","lang":"javascript","description":"Demonstrates the package.json setup and `next.config.js` configuration for using `ns-build` with a Next.js project, followed by the build command."},"warnings":[{"fix":"Ensure your Next.js project is compatible with Next.js v16 or later and update your AWS Lambda configuration to use Node.js 24. For earlier Next.js versions, use ns-build v2.x or earlier.","message":"Version 3.x of ns-build requires Next.js v16+ and upgrades the AWS Lambda runtime to Node.js 24.","severity":"breaking","affected_versions":">=3.0.1"},{"fix":"Update your Next.js project to v15 or later and ensure your AWS environment supports Node.js 22 for Lambda functions. Consider upgrading to ns-build v3.x and Node.js 24 for the latest support.","message":"Version 2.x of ns-build required Next.js v15+ and switched the AWS Lambda runtime to Node.js 22.","severity":"breaking","affected_versions":">=2.0.0 <3.0.0"},{"fix":"Add `output: 'standalone'` to your `next.config.js` configuration file to ensure the build output is in the expected format for the tool.","message":"The `next.config.js` file MUST include `output: 'standalone'` for `ns-build` to correctly prepare your Next.js application for serverless deployment.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Do not attempt to `import` or `require` symbols from `ns-build` in your JavaScript or TypeScript code. Interact with it solely as a command-line utility.","message":"This package is a CLI tool (a bash script) and does not expose JavaScript/TypeScript modules for programmatic import. Its primary interaction is via the command line, typically through `npm run build` or `npx ns-build build`.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Verify that your `next` peer dependency is satisfied (e.g., `^16.0.0` for `ns-build` v3) and that `output: 'standalone'` is correctly configured in your `next.config.js`.","cause":"This error typically indicates a mismatch between the `ns-build` tool's expected Next.js version and the one installed in your project, or an incorrect `output` configuration.","error":"Cannot find module 'next/dist/server/next-server'"},{"fix":"Inspect the detailed output preceding this error for specific Next.js build failures (e.g., linting errors, missing dependencies, incorrect configurations). Try running `next build` directly to isolate the issue.","cause":"A generic error indicating that the underlying build process invoked by the bash script failed. This could be due to issues within your Next.js project build itself.","error":"Error: Command failed with exit code 1"}],"ecosystem":"npm"}