Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Quasar or webpack build fails on ajv/dist/compile/codegen

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

Short answer

That path exists only in Ajv 8. The error means a package written for Ajv 8, usually ajv-keywords 5, was loaded next to an older Ajv 6 copy that npm placed at the top of node_modules. Run npm ls ajv to see who pulls which version, then install Ajv 8 yourself or override the one package that needs it.

  • Applies to Node.js 22, npm 10, ajv 8, ajv-keywords 5, webpack 5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List every copy of ajv in the tree and the package that asked for it. The line above ajv@6 tells you which parent is on the wrong side.

    npm ls ajv
    npm ls ajv-keywords
  2. 2Match what you see, then jump to its fix

    1. 1The require stack in the error names ajv-keywords, and npm ls ajv shows ajv@6 at the top level.ajv-keywords 5 is paired with a hoisted Ajv 6Fix
    2. 2npm ls ajv shows a package that lists ajv@6 even after you installed ajv@8.One dependency pins Ajv 6 and npm keeps itFix

What does the error look like?

  • Error: Cannot find module 'ajv/dist/compile/codegen'
  • Quasar Error: Cannot find module 'ajv/dist/compile/codegen'

Cause 1 of 2

ajv-keywords 5 is paired with a hoisted Ajv 6

1Check

ajv-keywords version 5 is written for Ajv 8, and version 3 is written for Ajv 6. When the copy of ajv that Node.js finds first is 6.x, the version 5 code asks for a file that Ajv 6 does not have.

npm ls ajv
node -p "require('ajv/package.json').version"

2Fix

Add Ajv 8 as a direct dependency so npm places it at the top level, then reinstall.

npm install --save-dev ajv@8
npm install

3Verify

The top-level ajv now reports 8.x and the build starts.

node -p "require('ajv/package.json').version"
npm ls ajv

Confirmed by github.com

Did this fix it?

Cause 2 of 2

One dependency pins Ajv 6 and npm keeps it

1Check

Find the parent from the npm ls output. Overrides in the root package.json replace the version a named parent asks for, and overrides inside installed dependencies are ignored.

npm ls ajv

2Fix

Override Ajv only below the parent that needs version 8, so other packages that still need Ajv 6 keep it. Replace parent-package with the name from npm ls, delete node_modules and the lockfile entry, and reinstall.

{
  "overrides": {
    "parent-package": {
      "ajv": "^8.0.0"
    }
  }
}

rm -rf node_modules package-lock.json
npm install

3Verify

npm ls ajv shows 8.x under that parent.

npm ls ajv

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Commit the lockfile and install with npm ci so every machine gets the same Ajv copies.
  • Add Ajv 8 as a direct dev dependency when a build tool needs it, instead of relying on whatever gets hoisted.
  • Run npm ls ajv after any major upgrade of webpack, schema-utils or your framework CLI.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Web apps

tsconfig rejects allowImportingTsExtensions

An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly

allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.