Quasar or webpack build fails on ajv/dist/compile/codegen
Error: 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.
Fix it fast
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-keywords2Match what you see, then jump to its fix
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 install3Verify
The top-level ajv now reports 8.x and the build starts.
node -p "require('ajv/package.json').version"
npm ls ajvConfirmed by github.com
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 ajv2Fix
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 install3Verify
npm ls ajv shows 8.x under that parent.
npm ls ajvConfirmed by docs.npmjs.com
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 fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fix