create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

Cannot find module 'ajv/dist/compile/codegen'

Open lsaffre opened this issue 1 year ago • 13 comments

Describe the bug

I am quite new to the world of npm. When I say "npx create-react-app my-app; cd my-app; npm start" as instructed on the Getting Started page, I get an error message "Cannot find module 'ajv/dist/compile/codegen'"

Did you try recovering your dependencies?

I had to manually say npm install --save-dev ajv to get it to work.

I report this as an issue because it's obviously not intended behaviour, and it's not a nice welcome to beginners. If this happens only on my machine, then I'd like to understand what's wrong with my environment.

Environment

I am using npm version 10.8.2 I did "npm install -g npm@latest" as recommended, removed the my-app directory and tried again, but the issue remains.

(dev) luc@yoga:~/work/my-app$ npm ls -g
/usr/local/lib
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

Environment Info:

current version of create-react-app: 5.0.1 running from /home/luc/.npm/_npx/c67e74de0542c87c/node_modules/create-react-app

System: OS: Linux 6.5 Ubuntu 22.04.4 LTS 22.04.4 LTS (Jammy Jellyfish) CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1185G7 @ 3.00GHz Binaries: Node: 20.15.1 - /usr/local/bin/node Yarn: 1.22.22 - /usr/local/bin/yarn npm: 10.8.2 - /usr/local/bin/npm Browsers: Chrome: Not Found npmPackages: react: ^18.3.1 => 18.3.1 react-dom: ^18.3.1 => 18.3.1 react-scripts: 5.0.1 => 5.0.1 npmGlobalPackages: create-react-app: Not Found

Steps to reproduce

As instructed on https://create-react-app.dev/docs/getting-started :

npx create-react-app my-app
cd my-app
npm start

Expected behavior

No error message and the browser starting at http://localhost:3000

Actual behavior

(dev) luc@yoga:~/work/my-app$ npm start

> [email protected] start
> react-scripts start

Cannot find module 'ajv/dist/compile/codegen'
Require stack:
- /home/luc/work/my-app/node_modules/ajv-keywords/dist/definitions/typeof.js
- /home/luc/work/my-app/node_modules/ajv-keywords/dist/keywords/typeof.js
- /home/luc/work/my-app/node_modules/ajv-keywords/dist/keywords/index.js
- /home/luc/work/my-app/node_modules/ajv-keywords/dist/index.js
- /home/luc/work/my-app/node_modules/schema-utils/dist/validate.js
- /home/luc/work/my-app/node_modules/schema-utils/dist/index.js
- /home/luc/work/my-app/node_modules/webpack-dev-server/lib/Server.js
- /home/luc/work/my-app/node_modules/react-scripts/scripts/start.js
(dev) luc@yoga:~/work/my-app$ 

lsaffre avatar Aug 07 '24 17:08 lsaffre

Run npm uninstall -g create-react-app to remove the global create-react-app package. Then, try using npx create-react-app my-app again.

npx will automatically download the latest version of create-react-app and use it to set up your project.

zinebelouarradi avatar Aug 13 '24 10:08 zinebelouarradi

Run npm uninstall -g create-react-app to remove the global create-react-app package. Then, try using npx create-react-app my-app again.

npx will automatically download the latest version of create-react-app and use it to set up your project.

Thanks for your suggestion. Unfortunately it didn't help. Your suggestion gave me the idea to try "sudo apt remove npm" followed by "sudo apt install npm". But this too didn't help.

lsaffre avatar Aug 13 '24 20:08 lsaffre

this problem happens to me also and i just migrate my app to the now version

MosheHM avatar Nov 12 '24 09:11 MosheHM

Run npm uninstall -g create-react-app to remove the global create-react-app package. Then, try using npx create-react-app my-app again.

npx will automatically download the latest version of create-react-app and use it to set up your project.

I have the same issue when trying to built a new app. I tried uninstalling the global create-react-app as well but with the same result.

Versions:

"react": "^19.0.0", "react-dom": "^19.0.0", "react-scripts": "5.0.1", "web-vitals": "^2.1.4" node -v -> v18.20.1 npm -v -> 10.5.1

Update

Manually installing the package (as mentioned here https://github.com/ajv-validator/ajv/issues/2443#issuecomment-2429810499) did the trick for me:

npm install ajv --save-dev

dana-c0914 avatar Dec 06 '24 09:12 dana-c0914

Hii , I am facing the same issue , I have tried several methods but it seems npm install ajv --save-dev is the only way for now

sanyam-saurabh avatar Dec 11 '24 05:12 sanyam-saurabh

same

patotoma avatar Dec 18 '24 05:12 patotoma

I have also acquired this issue - a few days ago for no appearant reason. npm install --save-dev ajv@^7 or similar fixes it for the project in question, it seems. There are lots of youtube videos with this solution, but I also need a permanent one. Reinstalling Node.js (upgrade from 20 to 22) didn't help. So I can't figure out if it is factors related to my machine.

jeppewl avatar Dec 19 '24 22:12 jeppewl

I also had the same problem. I solved it by running: npm install -g npm@latest (in the Node.js Command Prompt) and then trying npm start again ss Screenshot 2025-01-10 003307

MaNaNchotaliya avatar Jan 09 '25 19:01 MaNaNchotaliya

npm install -g npm@latest (which is currently v11.1.0 on Windows) did solved the npm start issue on a freshly created react-app using npx create-react-app.

But i'm still getting these error/failure during npx create-react-app:

Installing template dependencies using npm...
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
npm error node_modules/react
npm error   react@"^19.0.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"^18.0.0" from @testing-library/[email protected]
npm error node_modules/@testing-library/react
npm error   @testing-library/react@"^13.0.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error C:\Users\AdamN\AppData\Local\npm-cache\_logs\2025-01-30T00_58_47_692Z-eresolve-report.txt
npm error A complete log of this run can be found in: C:\Users\AdamN\AppData\Local\npm-cache\_logs\2025-01-30T00_58_47_692Z-debug-0.log
`npm install --no-audit --save @testing-library/jest-dom@^5.14.1 @testing-library/react@^13.0.0 @testing-library/user-event@^13.2.1 web-vitals@^2.1.0` failed

Where --force nor --legacy-peer-deps will still shows the same error/failure, but npm config set legacy-peer-deps true made it successful (which previously can't be started due to ajv-related issue). I wondered why npm config set legacy-peer-deps true shows a different result than --legacy-peer-deps.

Anyway, without npm config set legacy-peer-deps true, if i ignored the failure during npx create-react-app and tried to npm start it, it's no longer getting ajv issue, but i'm seeing this error now:

Failed to compile.

Module not found: Error: Can't resolve 'web-vitals' in 'C:\Data\Projects\NodeTest\client-react\src'
ERROR in ./src/reportWebVitals.js 5:4-24
Module not found: Error: Can't resolve 'web-vitals' in 'C:\Data\Projects\NodeTest\client-react\src'

webpack compiled with 1 error

anr2me avatar Jan 30 '25 02:01 anr2me

Run npm uninstall -g create-react-app to remove the global create-react-app package. Then, try using npx create-react-app my-app again. npx will automatically download the latest version of create-react-app and use it to set up your project.

I have the same issue when trying to built a new app. I tried uninstalling the global create-react-app as well but with the same result.

Versions:

"react": "^19.0.0", "react-dom": "^19.0.0", "react-scripts": "5.0.1", "web-vitals": "^2.1.4" node -v -> v18.20.1 npm -v -> 10.5.1

Update

Manually installing the package (as mentioned here ajv-validator/ajv#2443 (comment)) did the trick for me:

npm install ajv --save-dev

yes it works . thanks you i was stuck in it . but i want to that is it not the permanent solution for this issue or it is the the permanent solution.

alwaysabhishek avatar Feb 15 '25 21:02 alwaysabhishek

npm install ajv --save-dev THIS works for me

SumedhDV avatar Feb 17 '25 11:02 SumedhDV

npm install ajv --save-dev THIS works for me

ho thank you dear it helped me..

suresh2648 avatar Feb 24 '25 07:02 suresh2648

npm install ajv --save-dev

Also worked for me.

onyedikachi23 avatar Sep 01 '25 16:09 onyedikachi23