aws-amplify / aws-amplify/amplify-hosting

Nextjs build fails. [Error: ENOTEMPTY: directory not empty, rmdir '/codebuild/output/src615130554/src/nextpo/apps/next/node_modules/eslint-plugin-jsx-a11y/node_modules/.bin']

Open
#2,775 5 comments 1 reaction 0 assignees View on GitHub
bug frontend-builds ssr
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

### Before opening, please confirm:

- [X] I have checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-hosting/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-hosting/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-hosting/blob/master/CONTRIBUTING.md).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

### App Id

arn:aws:amplify:us-east-1:224875105023:apps/d11vufdm6y7riq

### Region

us-east-1

### Amplify Hosting feature

Not applicable

### Describe the bug

When the nextjs app is deployed and building the front-end phase, the command `next build` fails. This command is successful when I run it locally. The command will also succeed when deployed through Vercel. Only in amplify it fails.

This is the error log

```
2022-05-30T07:42:25.501Z [INFO]: [4/4] Building fresh packages...
2022-05-30T07:42:25.833Z [INFO]: Done in 57.34s.
2022-05-30T07:42:25.872Z [INFO]: # Completed phase: preBuild
# Starting phase: build
2022-05-30T07:42:25.872Z [INFO]: # Executing command: cd apps/next && yarn build
2022-05-30T07:42:26.015Z [INFO]: yarn run v1.22.0
2022-05-30T07:42:26.043Z [INFO]: $ next build
2022-05-30T07:42:27.040Z [INFO]: info - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
2022-05-30T07:42:27.469Z [INFO]: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
2022-05-30T07:42:27.487Z [INFO]: Attention: Next.js now collects completely anonymous telemetry regarding usage.
2022-05-30T07:42:27.487Z [INFO]: This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://nextjs.org/telemetry
2022-05-30T07:42:27.677Z [INFO]: info - Checking validity of types...
2022-05-30T07:42:32.549Z [INFO]: info - Creating an optimized production build...
2022-05-30T07:42:32.600Z [WARNING]:
2022-05-30T07:42:32.600Z [WARNING]: > Build error occurred
2022-05-30T07:42:32.601Z [WARNING]: [Error: ENOTEMPTY: directory not empty, rmdir '/codebuild/output/src615130554/src/nextpo/apps/next/node_modules/eslint-plugin-jsx-a11y/node_modules/.bin'] {
errno: -39,
code: 'ENOTEMPTY',
syscall: 'rmdir',
path: '/codebuild/output/src615130554/src/nextpo/apps/next/node_modules/eslint-plugin-jsx-a11y/node_modules/.bin'
}
2022-05-30T07:42:32.629Z [WARNING]: error Command failed with exit code 1.
2022-05-30T07:42:32.629Z [INFO]: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
2022-05-30T07:42:32.637Z [ERROR]: !!! Build failed
2022-05-30T07:42:32.638Z [ERROR]: !!! Non-Zero Exit Code detected
2022-05-30T07:42:32.638Z [INFO]: # Starting environment caching...
2022-05-30T07:42:32.639Z [INFO]: # Environment caching completed
Terminating logging...

```

### Expected behavior

The nextjs build should succeed.

### Reproduction steps

Connect the github repository to amplify hosting using amplify console. https://github.com/MiguelNiblock/nextpo/tree/main
Deploy and watch logs.

### Build Settings

```yaml
version: 1
frontend:
phases:
preBuild:
commands:
- yarn
build:
commands:
- cd apps/next && yarn build
artifacts:
baseDirectory: apps/next/.next
files:
- '**/*'
cache:
paths:
- node_modules/**/*
```

### Additional information

The nextjs app is in a yarn monorepo. I know amplify provides options for choosing monorepo directory, but the install command needs to be run from the rootDir, so the correct configuration must be to not choose a project directory. In my amplify.yml I adjusted the build command accordingly. (See above) And the output dir is also adjusted accordingly, to the output within the next directory. These details are not the problem, because the logs indicate the build command is initiated correctly. The error must be solely due to amplify's build environment.

Im trying to deploy a nextjs app to amplify. The same app is successfully deployed to Vercel, and the build command succeeds locally. It only fails in amplify.

This is the deployed app in Vercel. https://nextpo-zgdr.vercel.app/

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure from the linked nextpo repository using the shown amplify.yml, starting with the root yarn install and the apps/next build command. Compare the Amplify build log with local and Vercel runs, focusing on the ENOTEMPTY error under node_modules/eslint-plugin-jsx-a11y/node_modules/.bin; done means next build succeeds in Amplify.

Written by the indexing model from the issue text.

Assessment

Tech stack
nextjs, node.js
Domain
ci-cd, devops, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.