Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
harshitm1234 opened this issue Jun 3, 2024 · 41 comments
Open

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

harshitm1234 opened this issue Jun 3, 2024 · 41 comments

Comments

@harshitm1234
Copy link

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
@simoneconti
Copy link

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! [email protected] start: react-scripts start
    npm ERR! Exit status 1
    npm ERR!
    npm ERR! Failed at the [email protected] 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`

@Hsrf
Copy link

Hsrf commented Jun 3, 2024

Also facing the same issue...

@chitru
Copy link

chitru commented Jun 4, 2024

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

@achin178
Copy link

achin178 commented Jun 4, 2024

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

@intetm
Copy link

intetm commented Jun 4, 2024

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

@serheypast
Copy link

Has a similar issue

@scottdhicks
Copy link

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
Copy link

madibaT commented Jun 4, 2024

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

@vivekkumar677
Copy link

I`m getting same issue

@Venkat-juju
Copy link

same issue here...

@Rajesh6381
Copy link

Rajesh6381 commented Jun 6, 2024

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
Copy link

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
Copy link

ashiqfury commented Jun 6, 2024

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
Copy link

Same issue in azure build pipeline, local is working fine

@ubudragon
Copy link

same in gcp cloud build

@TrejGun
Copy link

TrejGun commented Jun 7, 2024

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

@intetm
Copy link

intetm commented Jun 7, 2024

Version 8.16 did NOT fix the issue

@TrejGun
Copy link

TrejGun commented Jun 7, 2024

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
Copy link

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
Copy link

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

this worked

@Alexander1987r
Copy link

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

@jasoniangreen
Copy link
Collaborator

Can everyone please try 8.16.0?

@jasoniangreen
Copy link
Collaborator

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
Copy link

intetm commented Jun 8, 2024

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
Copy link

TrejGun commented Jun 8, 2024

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
Copy link

ShiiRochi commented Jun 8, 2024

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

@jasoniangreen
Copy link
Collaborator

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
Copy link
Collaborator

jasoniangreen commented Jun 8, 2024

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
Copy link
Collaborator

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
Copy link

TrejGun commented Jun 8, 2024

try this one

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

not the smallest one but I do not have another

git clone [email protected]:Gemunion/nestjs-database.git
cd nestjs-database
npm i
npm run bootstrap
cd apps/sequelize
npm start

the fix is in this commit

Gemunion/nestjs-database@8c57a10

@toperrrrrrrr
Copy link

This fixed it for me, hope this helps:

npm install ajv@6 ajv-keywords@3

@pky92
Copy link

pky92 commented Jun 9, 2024

tried everything still now solved

@mumtyz
Copy link

mumtyz commented Jun 10, 2024

same issue here...

@TAPSIKATYAL
Copy link

TAPSIKATYAL commented Jun 10, 2024

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',
    }

@laurentperroteau
Copy link

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
Copy link

Stefanmle commented Jun 11, 2024

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'
    ]

@TAPSIKATYAL
Copy link

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

@TAPSIKATYAL
Copy link

Just run this command "npm install [email protected] [email protected] [email protected] --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
Copy link

That worked great. Thank you :)

@jasoniangreen
Copy link
Collaborator

jasoniangreen commented Jun 12, 2024

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
Copy link

Just run this command "npm install [email protected] [email protected] [email protected] --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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests