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 exit code 1: node_modules/.bin/next build
warn - Invalid next.config.js options detected:
- The root value has an unexpected property, target, which is not in the list of allowed properties (amp, analyticsId, assetPrefix, basePath, cleanDistDir, compiler, compress, crossOrigin, devIndicators, distDir, env, eslint, excludeDefaultMomentLocales, experimental, exportPathMap, future, generateBuildId, generateEtags, headers, httpAgentOptions, i18n, images, onDemandEntries, optimizeFonts, output, outputFileTracing, pageExtensions, poweredByHeader, productionBrowserSourceMaps, publicRuntimeConfig, reactStrictMode, redirects, rewrites, sassOptions, serverRuntimeConfig, staticPageGenerationTimeout, swcMinify, trailingSlash, typescript, useFileSystemPublicRoutes, webpack).
See more info here: https://nextjs.org/docs/messages/invalid-next-config
warn - The `target` config is deprecated and will be removed in a future version.
See more info here https://nextjs.org/docs/messages/deprecated-target-config
error - ESLint must be installed in order to run during builds: yarn add --dev eslint
Failed to compile.
./pages/_app.tsx:3:29
Type error: Cannot find module '@mui/material' or its corresponding type declarations.
1 | import "../styles/globals.css";
2 |
> 3 | import { CssBaseline } from "@mui/material";
| ^
4 | import { StyledEngineProvider, ThemeProvider } from "@mui/material/styles";
5 | import type { AppProps } from "next/app";
6 | import { appWithTranslation } from "next-i18next";
> Build error occurred
Error: Call retries were exceeded
at ChildProcessWorker.initialize (C:Usersbruno.cruzDocumentsINGRESSE-COMrepofinance-webnode_modulesnextdistcompiledjest-workerindex.js:1:11661)
at ChildProcessWorker._onExit (C:Usersbruno.cruzDocumentsINGRESSE-COMrepofinance-webnode_modulesnextdistcompiledjest-workerindex.js:1:12599)
at ChildProcess.emit (events.js:315:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
type: 'WorkerError'
}
info - Loaded env from C:Usersbruno.cruzDocumentsINGRESSE-COMrepofinance-web.env
info - SWC minify release candidate enabled. https://nextjs.link/swcmin
info - Linting and checking validity of types...
at makeError (C:Usersbruno.cruz.serverlesscomponentsregistrynpm@[email protected]_modules@sls-nextserverless-componentnode_modulesexecaliberror.js:59:11)
at handlePromise (C:Usersbruno.cruz.serverlesscomponentsregistrynpm@[email protected]_modules@sls-nextserverless-componentnode_modulesexecaindex.js:114:26)
at processTicksAndRejections (internal/process/task_queues.js:93:5) {
shortMessage: 'Command failed with exit code 1: node_modules/.bin/next build',
command: 'node_modules/.bin/next build',
exitCode: 1,
signal: undefined,
signalDescription: undefined,
stdout: 'info - Loaded env from C:\Users\bruno.cruz\Documents\INGRESSE-COM\repo\finance-web\.envn' +
'info - SWC minify release candidate enabled. https://nextjs.link/swcminn' +
'info - Linting and checking validity of types...',
stderr: 'warn - Invalid next.config.js options detected: n' +
' - The root value has an unexpected property, target, which is not in the list of allowed properties (amp, analyticsId, assetPrefix, basePath, cleanDistDir, compiler, compress, crossOrigin, devIndicators, distDir, env, eslint, excludeDefaultMomentLocales, experimental, exportPathMap, future, generateBuildId, generateEtags, headers, httpAgentOptions, i18n, images, onDemandEntries, optimizeFonts, output, outputFileTracing, pageExtensions, poweredByHeader, productionBrowserSourceMaps, publicRuntimeConfig, reactStrictMode, redirects, rewrites, sassOptions, serverRuntimeConfig, staticPageGenerationTimeout, swcMinify, trailingSlash, typescript, useFileSystemPublicRoutes, webpack).n' +
'n' +
'See more info here: https://nextjs.org/docs/messages/invalid-next-confign' +
'warn - The `target` config is deprecated and will be removed in a future version.n' +
'See more info here https://nextjs.org/docs/messages/deprecated-target-confign' +
'error - ESLint must be installed in order to run during builds: yarn add --dev eslintn' +
'Failed to compile.n' +
'n' +
'./pages/_app.tsx:3:29n' +
"Type error: Cannot find module '@mui/material' or its corresponding type declarations.n" +
'n' +
'x1B[0m x1B[90m 1 | x1B[39mx1B[36mimportx1B[39m x1B[32m"../styles/globals.css"x1B[39mx1B[33m;x1B[39mx1B[0mn' +
'x1B[0m x1B[90m 2 | x1B[39mx1B[0mn' +
'x1B[0mx1B[31mx1B[1m>x1B[22mx1B[39mx1B[90m 3 | x1B[39mx1B[36mimportx1B[39m { x1B[33mCssBaselinex1B[39m } x1B[36mfromx1B[39m x1B[32m"@mui/material"x1B[39mx1B[33m;x1B[39mx1B[0mn' +
'x1B[0m x1B[90m | x1B[39m x1B[31mx1B[1m^x1B[22mx1B[39mx1B[0mn' +
'x1B[0m x1B[90m 4 | x1B[39mx1B[36mimportx1B[39m { x1B[33mStyledEngineProviderx1B[39mx1B[33m,x1B[39m x1B[33mThemeProviderx1B[39m } x1B[36mfromx1B[39m x1B[32m"@mui/material/styles"x1B[39mx1B[33m;x1B[39mx1B[0mn' +
'x1B[0m x1B[90m 5 | x1B[39mx1B[36mimportx1B[39m type { x1B[33mAppPropsx1B[39m } x1B[36mfromx1B[39m x1B[32m"next/app"x1B[39mx1B[33m;x1B[39mx1B[0mn' +
'x1B[0m x1B[90m 6 | x1B[39mx1B[36mimportx1B[39m { appWithTranslation } x1B[36mfromx1B[39m x1B[32m"next-i18next"x1B[39mx1B[33m;x1B[39mx1B[0mn' +
'n' +
'> Build error occurredn' +
'Error: Call retries were exceededn' +
' at ChildProcessWorker.initialize (C:\Users\bruno.cruz\Documents\INGRESSE-COM\repo\finance-web\node_modules\next\dist\compiled\jest-worker\index.js:1:11661)n' +
' at ChildProcessWorker._onExit (C:\Users\bruno.cruz\Documents\INGRESSE-COM\repo\finance-web\node_modules\next\dist\compiled\jest-worker\index.js:1:12599)n' +
' at ChildProcess.emit (events.js:315:20)n' +
' at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {n' +
" type: 'WorkerError'n" +
'}',
failed: true,
timedOut: false,
isCanceled: false,
killed: false
}
11s » financeWebFront » Error: Command failed with exit code 1: node_modules/.bin/next build
warn - Invalid next.config.js options detected:
- The root value has an unexpected property, target, which is not in the list of allowed properties (amp, analyticsId, assetPrefix, basePath, cleanDistDir, compiler, compress, crossOrigin, devIndicators, distDir, env, eslint, excludeDefaultMomentLocales, experimental, exportPathMap, future, generateBuildId, generateEtags, headers, httpAgentOptions, i18n, images, onDemandEntries, optimizeFonts, output, outputFileTracing, pageExtensions, poweredByHeader, productionBrowserSourceMaps, publicRuntimeConfig, reactStrictMode, redirects, rewrites, sassOptions, serverRuntimeConfig, staticPageGenerationTimeout, swcMinify, trailingSlash, typescript, useFileSystemPublicRoutes, webpack).
See more info here: https://nextjs.org/docs/messages/invalid-next-config
warn - The `target` config is deprecated and will be removed in a future version.
See more info here https://nextjs.org/docs/messages/deprecated-target-config
error - ESLint must be installed in order to run during builds: yarn add --dev eslint
Failed to compile.
./pages/_app.tsx:3:29
Type error: Cannot find module '@mui/material' or its corresponding type declarations.
1 | import "../styles/globals.css";
2 |
> 3 | import { CssBaseline } from "@mui/material";
| ^
4 | import { StyledEngineProvider, ThemeProvider } from "@mui/material/styles";
5 | import type { AppProps } from "next/app";
6 | import { appWithTranslation } from "next-i18next";
> Build error occurred
Error: Call retries were exceeded
at ChildProcessWorker.initialize (C:Usersbruno.cruzDocumentsINGRESSE-COMrepofinance-webnode_modulesnextdistcompiledjest-workerindex.js:1:11661)
at ChildProcessWorker._onExit (C:Usersbruno.cruzDocumentsINGRESSE-COMrepofinance-webnode_modulesnextdistcompiledjest-workerindex.js:1:12599)
at ChildProcess.emit (events.js:315:20)
at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12) {
type: 'WorkerError'
}
info - Loaded env from C:Usersbruno.cruzDocumentsINGRESSE-COMrepofinance-web.env
info - SWC minify release candidate enabled. https://nextjs.link/swcmin
info - Linting and checking validity of types...
I’m using aws configure to set my AWS credentials.
My serverless.yml file is as follow,
myNextApplication:
component: "@sls-next/[email protected]"
How should I deploy my app to AWS cloud with a serverless framework?
Thanks.
2
Answers
You need to install the missing dependency
npm i @mui/material
oryarn add @mui/material
. That should fix it. Also, check yournext.config.js
file. It seems you are adding some things there which do not belong.More so, to deploy to AWS, just use AWS Amplify. Read the docs to see how to set up with Next.js. It’s very simple. Just deploy your code to github, connect to your repo via Amplify and then allow it to build your project for you.
Basically serverless nextjs is dead and the newest version are not supported
If AWS lambda is your unique option then try reverting the nextjs version to 11.x