ajv-validator / ajv

The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)
https://ajv.js.org
MIT License
13.55k stars 867 forks source link

Error: Cannot find module 'ajv/dist/compile/codegen' #2443

Open harshitm1234 opened 1 month ago

harshitm1234 commented 1 month ago

While build process using Craco Getting error Cannot find module 'ajv/dist/compile/codegen'

Below is the call stack generated By craco Build using node version "v16.15.1" and npm version "8.11.0". This issue is reproducible once we delete node_modules and package-lock.json. Installing packages and using craco build will result in the above error. ajv is not used as dependency in the project.

Require stack:

Screenshot 2024-06-03 at 8 09 02 PM
simoneconti commented 1 month ago

Same issue, without craco.

`Cannot find module 'ajv/dist/compile/codegen' Require stack:

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\xxx\AppData\Roaming\npm-cache_logs\2024-06-03T15_19_07_906Z-debug.log`

Hsrf commented 1 month ago

Also facing the same issue...

chitru commented 1 month ago

Project that was working suddenly starting giving this same error..

achin178 commented 1 month ago

I also facing the same problem. I can currently use: npm install ajv --save-dev as a workaround.

intetm commented 1 month ago

Seems like new version: 8.15.0 causes this bug. Our project stopped building however nothing had been changed.

serheypast commented 1 month ago

Has a similar issue

scottdhicks commented 1 month ago

Seems like new version: 8.15.0 causes this bug. Our project stopped building however nothing had been changed.

8.14 started the issue for my project. We pinned to 8.13 for now to get things to work.

Any updates on a fix?

madibaT commented 1 month ago

We saw the same issue on our side. We had to pin to 8.14

vivekkumar677 commented 1 month ago

I`m getting same issue

Venkat-juju commented 1 month ago

same issue here...

Rajesh6381 commented 1 month ago

same issue here...

if you are use like this npm install --force --legacy-peer-deps, try to use --force only npm install --force

Venkat-juju commented 1 month ago

same issue here...

if you are use like this npm install --legacy-peer-deps, try to use --force npm install --force

Thanks mate!! That solved my issue. you saved my day!

ashiqfury commented 1 month ago

same issue here...

if you are use like this npm install --legacy-peer-deps, try to use --force npm install --force

Same issue here also. --force command helped me. Thanks for your valueable help.

SaiPrasannaCdc commented 1 month ago

Same issue in azure build pipeline, local is working fine

ubudragon commented 4 weeks ago

same in gcp cloud build

TrejGun commented 4 weeks ago

have that same with jest in one project and webpack in another project

intetm commented 4 weeks ago

Version 8.16 did NOT fix the issue

TrejGun commented 4 weeks ago

the problem is not in this module it is in ajv-keywords

telegram-cloud-photo-size-1-5123292309750918233-y

ajv-keywords tries to get v8 but receives v6 but why so? ajv is a peer dependency in ajv-keywords, it is not installed together and you all are seeing this package for the first time so it was installed by other package so that means some package in the tree got updated and now the closest version in the three is v8

I have found a solution to add "ajv": "8.8.2" into my package.json and it worked in two completely different projects

tomasmalio commented 4 weeks ago

I modified my Dockerfile (RUN npm install --legacy-peer-deps to RUN npm install --force) and nothing happened. I don't understand why this problem appears without calling it. I'm installing the "ajv": "8.8.2" as @TrejGun said if you install "ajv": "8.8.2" it works. Thanks @TrejGun

SaiPrasannaCdc commented 4 weeks ago

add "ajv": "8.8.2" into my package.json

this worked

Alexander1987r commented 4 weeks ago

Такая же проблема при запуске React.Как кто боролся подскажите?

jasoniangreen commented 4 weeks ago

Can everyone please try 8.16.0?

jasoniangreen commented 4 weeks ago

We saw the same issue on our side. We had to pin to 8.14

Please update to 8.16.0 and let me know.

intetm commented 4 weeks ago

We saw the same issue on our side. We had to pin to 8.14

Please update to 8.16.0 and let me know.

I wrote above that version 8.16 did not help either.

TrejGun commented 4 weeks ago

We saw the same issue on our side. We had to pin to 8.14

Please update to 8.16.0 and let me know.

this does not help

ShiiRochi commented 4 weeks ago

Try freezing ajv to ~8.14.0 and webpack to ~5.82.1. Playing only with ajv could not help.

jasoniangreen commented 4 weeks ago

Is it possible one of your other dependencies is pulling in the broken version (8.15.0) because 8.16.0 is identical to 8.14.0 apart from the version number (see this diff tool).

If you look at your lock files do you see multiple versions of AJV mentioned?

jasoniangreen commented 4 weeks ago

the problem is not in this module it is in ajv-keywords

telegram-cloud-photo-size-1-5123292309750918233-y

ajv-keywords tries to get v8 but receives v6 but why so? ajv is a peer dependency in ajv-keywords, it is not installed together and you all are seeing this package for the first time so it was installed by other package so that means some package in the tree got updated and now the closest version in the three is v8

I have found a solution to add "ajv": "8.8.2" into my package.json and it worked in two completely different projects

I just saw this, maybe this issue is not related to the broken 8.15.0 release? I will look into it further. Maybe there's an issue that ajv-keywords is pointing at an old version of AJV.

jasoniangreen commented 4 weeks ago

Oh and it would be much appreciated if someone can give me a simple example repo that reproduces the issue. With as few other dependencies as possible thanks!

TrejGun commented 4 weeks ago

try this one

https://github.com/Gemunion/nestjs-database

not the smallest one but I do not have another

git clone git@github.com:Gemunion/nestjs-database.git
cd nestjs-database
npm i
npm run bootstrap
cd apps/sequelize
npm start

the fix is in this commit

https://github.com/Gemunion/nestjs-database/commit/8c57a106efb70d19b520f45a25639615b8b2c12b

toperrrrrrrr commented 3 weeks ago

This fixed it for me, hope this helps:

npm install ajv@6 ajv-keywords@3

pky92 commented 3 weeks ago

tried everything still now solved

mumtyz commented 3 weeks ago

same issue here...

TAPSIKATYAL commented 3 weeks ago

We are facing same issue from 6th June 2024. We are using ajv 8.16.0 and ajv-keywords 5.1.0 version. Suddenly it stopped working when we were creating new build. Posting error stack to check the issue. Node version used 14.18.3.

internal/modules/cjs/loader.js:905 throw err; ^

Error: Cannot find module 'ajv/dist/compile/codegen' Require stack:

laurentperroteau commented 3 weeks ago

Add a newer version of ajv works for me too but it's cleaner to:

npm install ajv --save-dev and copying it in override in package.json

  "devDependencies": {
    ...
    "ajv": "^8.16.0",
    ...
  },
  "overrides": {
    "ajv": "^8.16.0"
  },

This explicitly indicates you force your dependencies to use this version https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides

Stefanmle commented 3 weeks ago

I also get the same error, and I can´t even find "ajv" anywhere in my solution. Nothing with my build files or package.json has changed, it just stopped working from one day to another.

react-scripts build

node:internal/modules/cjs/loader:1143 throw err; ^

Error: Cannot find module 'ajv/dist/compile/codegen' Require stack:

TAPSIKATYAL commented 3 weeks ago

please check your package.lock.json. There you will find "ajv" package. Hopefully, it should help you.

TAPSIKATYAL commented 3 weeks ago

Just run this command "npm install ajv@8.16.0 ajv-keywords@5.1.0 schema-utils@4.2.0 --save-dev" . It will add package in package.json file and then it will point to 8.16v only, hopefully will not give error . But you can build it to see if any error comes.

Stefanmle commented 3 weeks ago

That worked great. Thank you :)

jasoniangreen commented 3 weeks ago

Add a newer version of ajv works for me too but it's cleaner to:

npm install ajv --save-dev and copying it in override in package.json

  "devDependencies": {
    ...
    "ajv": "^8.16.0",
    ...
  },
  "overrides": {
    "ajv": "^8.16.0"
  },

This explicitly indicates you force your dependencies to use this version https://docs.npmjs.com/cli/v9/configuring-npm/package-json#overrides

The only explanation I can think of, if it is related to the broken release 8.15.0 is that there is some lag with these downstream dependencies and somewhere the wrong version is still being picked up. One of the examples shared had installed version 6 of AJV (very old) so that should have nothing to do with the bad release.

edit: Also I noted some older versions of node being used, it would be interesting, if possible, to try a newer version. AJV recently removed node 12 and 14 from our testing matrix. This doesn't mean we did anything specific to break on older versions of node, but that we're not focussed on them anymore.

messyKassaye commented 2 weeks ago

Just run this command "npm install ajv@8.16.0 ajv-keywords@5.1.0 schema-utils@4.2.0 --save-dev" . It will add package in package.json file and then it will point to 8.16v only, hopefully will not give error . But you can build it to see if any error comes.

this works for me. Thanks

jasoniangreen commented 5 days ago

Has this issue died off? I'm wondering if there is a real issue that needs addressing or if it was just the nature of deep dependency chains that the bad version took a while to get out of the system (and in some cases people needed overrides to get there faster)?

MashiGitCat commented 4 days ago

same issue here...

if you are use like this npm install --force --legacy-peer-deps, try to use --force only npm install --force

same issue here...

if you are use like this npm install --force --legacy-peer-deps, try to use --force only npm install --force

Thanks ! It worked!

RaSah673 commented 1 day ago

this "npm install ajv --save-dev" resolves the issue

WalaceRamosdev commented 1 day ago

Eu também estou enfrentando o mesmo problema. Atualmente, posso usar: npm install ajv --save-dev como solução alternativa.

essa solução me atendeu bem...OBRIGADO !