Error: Cannot find module 'ajv/dist/compile/codegen'
harshitm1234 opened this issue · 52 comments
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:
- /node_modules/ajv-keywords/dist/definitions/typeof.js
- /node_modules/ajv-keywords/dist/keywords/typeof.js
- /node_modules/ajv-keywords/dist/keywords/index.js
- /node_modules/ajv-keywords/dist/index.js
- /node_modules/schema-utils/dist/validate.js
- /node_modules/schema-utils/dist/index.js
- /node_modules/mini-css-extract-plugin/dist/index.js
- /node_modules/react-scripts/config/webpack.config.js
- /node_modules/@craco/craco/dist/lib/cra.js
- /node_modules/@craco/craco/dist/scripts/build.js
![Screenshot 2024-06-03 at 8 09 02 PM](https://private-user-images.githubusercontent.com/36616432/336115993-95f7211e-774c-4209-9e91-9b0a923f2ae4.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mjc4MDEzNDgsIm5iZiI6MTcyNzgwMTA0OCwicGF0aCI6Ii8zNjYxNjQzMi8zMzYxMTU5OTMtOTVmNzIxMWUtNzc0Yy00MjA5LTllOTEtOWIwYTkyM2YyYWU0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDEwMDElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQxMDAxVDE2NDQwOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTEwM2M5ZDVjMWVmYmVhNGJkNmRjMjNjNDBiMjAyZmQ5ZjkwZjZmOTNlOGVlNGViZTdkYjQ0ZGU2N2M0YjNkMjkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.ydjbGEpcOZdvOLL9WfNGQBgMBpVmwGDZiy_IKAz2r1Q)
Same issue, without craco.
`Cannot find module 'ajv/dist/compile/codegen'
Require stack:
- C:\Users\xxx\git\yyy\zzz\node_modules\ajv-keywords\dist\definitions\typeof.js
- C:\Users\xxx\git\yyy\zzz\node_modules\ajv-keywords\dist\keywords\typeof.js
- C:\Users\xxx\git\yyy\zzz\node_modules\ajv-keywords\dist\keywords\index.js
- C:\Users\xxx\git\yyy\zzz\node_modules\ajv-keywords\dist\index.js
- C:\Users\xxx\git\yyy\zzz\node_modules\schema-utils\dist\validate.js
- C:\Users\xxx\git\yyy\zzz\node_modules\schema-utils\dist\index.js
- C:\Users\xxx\git\yyy\zzz\node_modules\webpack-dev-server\lib\Server.js
- C:\Users\xxx\git\yyy\zzz\node_modules\react-scripts\scripts\start.js
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! zzz@1.0.0 start:react-scripts start
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the zzz@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
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`
Also facing the same issue...
Project that was working suddenly starting giving this same error..
I also facing the same problem.
I can currently use:
npm install ajv --save-dev
as a workaround.
Seems like new version: 8.15.0 causes this bug. Our project stopped building however nothing had been changed.
Has a similar issue
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?
We saw the same issue on our side. We had to pin to 8.14
I`m getting same issue
same issue here...
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 --legacy-peer-deps
, try to use --forcenpm install --force
Thanks mate!! That solved my issue. you saved my day!
same issue here...
if you are use like this
npm install --legacy-peer-deps
, try to use --forcenpm install --force
Same issue here also. --force command helped me. Thanks for your valueable help.
Same issue in azure build pipeline, local is working fine
same in gcp cloud build
have that same with jest in one project and webpack in another project
Version 8.16 did NOT fix the issue
the problem is not in this module it is in ajv-keywords
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
add
"ajv": "8.8.2"
into my package.json
this worked
Такая же проблема при запуске React.Как кто боролся подскажите?
Can everyone please try 8.16.0?
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.
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.
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
Try freezing ajv
to ~8.14.0
and webpack
to ~5.82.1
. Playing only with ajv
could not help.
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?
the problem is not in this module it is in ajv-keywords
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.
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!
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
This fixed it for me, hope this helps:
npm install ajv@6 ajv-keywords@3
tried everything still now solved
same issue here...
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:
- \node_modules\ajv-keywords\dist\definitions\typeof.js
- \node_modules\ajv-keywords\dist\keywords\typeof.js
-\node_modules\ajv-keywords\dist\keywords\index.js - \node_modules\ajv-keywords\dist\index.js
- \node_modules\schema-utils\dist\validate.js
- \node_modules\schema-utils\dist\index.js
- \node_modules\mini-css-extract-plugin\dist\index.js
-\node_modules\react-scripts\config\webpack.config.js - \node_modules\react-scripts\scripts\build.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
at Function.Module._load (internal/modules/cjs/loader.js:746:27)
at Module.require (internal/modules/cjs/loader.js:974:19)
at require (internal/modules/cjs/helpers.js:93:18)
at Object. (\node_modules\ajv-keywords\dist\definitions\typeof.js:3:19)
at Module._compile (internal/modules/cjs/loader.js:1085:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Module.require (internal/modules/cjs/loader.js:974:19) {
code: 'MODULE_NOT_FOUND',
}
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
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:
- /home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/ajv-keywords/dist/definitions/typeof.js
- /home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/ajv-keywords/dist/keywords/typeof.js
- /home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/ajv-keywords/dist/keywords/index.js
- /home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/ajv-keywords/dist/index.js
- /home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/schema-utils/dist/validate.js
- /home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/schema-utils/dist/index.js
- /home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/mini-css-extract-plugin/dist/index.js
- /home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/react-scripts/config/webpack.config.js
- /home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/react-scripts/scripts/build.js
at Module._resolveFilename (node:internal/modules/cjs/loader:1140:15)
at Module._load (node:internal/modules/cjs/loader:981:27)
at Module.require (node:internal/modules/cjs/loader:1231:19)
at require (node:internal/modules/helpers:177:18)
at Object. (/home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/ajv-keywords/dist/definitions/typeof.js:3:19)
at Module._compile (node:internal/modules/cjs/loader:1364:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
at Module.load (node:internal/modules/cjs/loader:1203:32)
at Module._load (node:internal/modules/cjs/loader:1019:12)
at Module.require (node:internal/modules/cjs/loader:1231:19) ***
code: 'MODULE_NOT_FOUND',
requireStack: [
'/home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/ajv-keywords/dist/definitions/typeof.js',
'/home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/ajv-keywords/dist/keywords/typeof.js',
'/home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/ajv-keywords/dist/keywords/index.js',
'/home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/ajv-keywords/dist/index.js',
'/home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/schema-utils/dist/validate.js',
'/home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/schema-utils/dist/index.js',
'/home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/mini-css-extract-plugin/dist/index.js',
'/home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/react-scripts/config/webpack.config.js',
'/home/runner/work/mmk-dose-monitoring-web-admin-creative-tim-ts/mmk-dose-monitoring-web-admin-creative-tim-ts/node_modules/react-scripts/scripts/build.js'
]
please check your package.lock.json. There you will find "ajv" package. Hopefully, it should help you.
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.
That worked great. Thank you :)
Add a newer version of
ajv
works for me too but it's cleaner to:
npm install ajv --save-dev
and copying it inoverride
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.
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
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)?
same issue here...
if you are use like this
npm install --force --legacy-peer-deps
, try to use --force onlynpm install --force
same issue here...
if you are use like this
npm install --force --legacy-peer-deps
, try to use --force onlynpm install --force
Thanks ! It worked!
this "npm install ajv --save-dev" resolves the issue
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 !
I'm going to assume this is resolved and anyone needing to do npm install ajv --save-dev
could also resolve by doing a clean npm install since all downstream dependencies should have the fixed version by now.
If you use npm update --legacy-peer-deps
, you can try pnpm i
It work for me
This fixed it for me, hope this helps:
npm install ajv@6 ajv-keywords@3
This worked for me.FYI I was working on a jest project and suddenly my working project stopped. Thanks!!
Use this to resolve this error:
npm install ajv --save-dev
same issue here...
if you are use like this
npm install --force --legacy-peer-deps
, try to use --force onlynpm install --force
Thanks. It solved my issue too.