2024 06 29 User faces ERESOLVE error deploying Yarn Vite React to GitHub Pages - bizkite-co/handterm GitHub Wiki
original file name: Codeium Chat - jDjNcbmbJGmgMlbn15vSwbkT4KLwz39r.md
summary: The chat revolves around a user facing an ERESOLVE error due to a dependency conflict when deploying a Yarn Vite React static website to GitHub Pages using AWS CDK. The assistant provides detailed explanations and suggests solutions, including using --legacy-peer-deps
with npm or switching entirely to Yarn. The user expresses a desire to remove npm in favor of Yarn and seeks guidance on how to transition fully to using Yarn in the project to avoid conflicts and ensure consistency. The assistant offers clear steps, such as removing package-lock.json
, updating documentation, configuring scripts, using Yarn for global packages, educating team members, and utilizing yarn dlx
instead of npx
to achieve this transition smoothly.
date: 2024-06-29T14:09
Note: This is purely the output of the chat conversation and does not contain any raw data, codebase snippets, etc. used to generate the output.
User at 2:09 pm, Jun 29, 2024
When I deploy my Yarn Vite React static website with AWS CDK subdirectory to GitHub Pages I get this error:
Run npm install
2
npm install
3
shell: /usr/bin/bash -e {0}
4
npm error code ERESOLVE
5
npm error ERESOLVE unable to resolve dependency tree
6
npm error
7
npm error While resolving: [email protected]
8
npm error Found: [email protected]
9
npm error node_modules/react
10
npm error react@"^18.2.0" from the root project
11
npm error
12
npm error Could not resolve dependency:
13
npm error peer react@"^16.9.0 || ^17.0.0" from @testing-library/[email protected]
14
npm error node_modules/@testing-library/react-hooks
15
npm error dev @testing-library/react-hooks@"^8.0.1" from the root project
16
npm error
17
npm error Fix the upstream dependency conflict, or retry
18
npm error this command with --force or --legacy-peer-deps
19
npm error to accept an incorrect (and potentially broken) dependency resolution.
20
npm error
21
npm error
22
npm error For a full report see:
23
npm error /home/runner/.npm/_logs/2024-06-29T21_05_42_279Z-eresolve-report.txt
24
25
npm error A complete log of this run can be found in: /home/runner/.npm/_logs/2024-06-29T21_05_42_279Z-debug-0.log
26
Error: Process completed with exit code 1.
Codeium at 2:10 pm, Jun 29, 2024
The error you're encountering occurs because of a dependency resolution conflict within npm. The root of the issue is that @testing-library/react-hooks
specifies it requires a peer dependency of React version ^16.9.0
or ^17.0.0
, but your project uses React version 18.3.1
. This version mismatch leads to the failure during the dependency resolution process.
Given your use of Yarn and npm in different contexts, here are a couple of solutions you can try to resolve this issue:
If you prefer to stick with npm for installing your dependencies, you can bypass the peer dependency conflict by using the --legacy-peer-deps
option. This option tells npm to ignore peer dependency conflicts. You can modify your GitHub Actions workflow file to include this option when running npm install
:
- name: Install dependencies
run: npm install --legacy-peer-deps
This approach allows npm to install dependencies without resolving the peer dependency conflict, which should let your deployment process proceed. However, be aware that this might lead to runtime issues if @testing-library/react-hooks
is not compatible with React version 18.3.1
.
Since your project uses Yarn, and Yarn is generally more lenient with peer dependencies than npm, switching to Yarn for your GitHub Actions workflow may resolve this issue without further configuration changes. Yarn's default behavior is similar to using --legacy-peer-deps
in npm, but it integrates better with projects already using Yarn. Update your GitHub Actions workflow file to use Yarn commands:
- name: Install dependencies
run: yarn install
Make sure your project's root directory contains a yarn.lock
file and potentially adjust any subsequent steps in your workflow that rely on npm to use Yarn commands instead.
Consider checking if there's an updated version of @testing-library/react-hooks
or any other related packages that adds support for React 18. Updating these packages might resolve the dependency conflict without requiring workarounds. You can check for updates by running:
yarn upgrade-interactive --latest
This command provides an interactive UI to select package updates, helping to ensure compatibility with React 18.
Choosing between these options depends on your project's requirements and your preference for handling dependencies.
User at 2:36 pm, Jun 29, 2024
What if I want to remove npm
? Some tools assume npm
is being used and just run it and I have to keep removing the package-lock.json
I want to just use yarn
if I can.
Codeium at 2:37 pm, Jun 29, 2024
If you want to fully commit to using Yarn and avoid confusion or issues with npm
, you can take several steps to ensure that Yarn is used exclusively for dependency management and script execution in your project. Here are some approaches to minimize inadvertent use of npm
:
You've already noted the need to remove package-lock.json
to avoid conflicts between package managers. Ensure that yarn.lock
is committed to your repository to track dependency versions accurately.
Remove-Item package-lock.json # Removes package-lock.json if exists
git add yarn.lock
git commit -m "Use Yarn for dependency management"
Clearly state in your README.md
and any contribution guidelines that Yarn is the package manager for the project. This can help set the expectation for other developers working on or contributing to the project.
## Development Setup
This project uses [Yarn](https://yarnpkg.com/) for dependency management. Please ensure you have Yarn installed on your development machine.
To install dependencies, run:
```bash
yarn install
### 3. **Configure Build and Deployment Scripts**
Ensure all scripts in your `package.json`, CI/CD pipelines (like GitHub Actions), and any other automated processes use Yarn commands instead of `npm`. This change helps enforce the use of Yarn across all development and deployment workflows.
For GitHub Actions, you can switch to Yarn by updating the workflow files:
```yaml
- name: Install dependencies
run: yarn install
- name: Build
run: yarn build
If you have global packages installed with npm
, consider reinstalling them with Yarn. Note that Yarn handles global packages differently from npm, so you might not need to use global installations as frequently. For packages that need to be globally accessible, use:
yarn global add package-name
Remember to remove the npm-installed global packages to avoid duplicates.
If you're working in a team, ensure all members are aware of the decision to use Yarn exclusively. Consider holding a brief session or sharing documentation on Yarn's benefits and how to use it for common tasks.
For running packages that would typically be executed with npx
, you can use yarn dlx
. This command allows you to execute a package binary without permanently installing it globally:
yarn dlx package-name
Some development tools or IDEs (Integrated Development Environments) might default to using npm
. Check the settings of your development environment to switch to Yarn if possible. For example, in Visual Studio Code, you might adjust task configurations that default to npm.
By taking these steps, you can help ensure that Yarn is the primary and sole package manager used in your project, minimizing the risks and confusion associated with using multiple package managers.