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' #385

Open
developer-73 opened this issue Mar 30, 2023 · 2 comments
Open

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

developer-73 opened this issue Mar 30, 2023 · 2 comments

Comments

@developer-73
Copy link

developer-73 commented Mar 30, 2023

I am facing this build error in "ajv-keywords" after installing packages with npm install --legacy-peer-deps
Error: Cannot find module 'ajv/dist/compile/codegen'

Background:

Consider the following dependency trees:

|__@eslint
|__avj@6.12.6          <<<<<---- |
|__ajv-keywords@5.1.0       >>---^  Incompatible with ajv@6.12.6
|__schema-utils@4.0.0
         |___ajv@8.12.0
|__@eslint
      |__avj@6.12.6
|__ajv@8.12.0            <<<<<---- |
|__ajv-keywords@5.1.0         >>---^  Compatible with ajv@8.12.0
|__schema-utils@4.0.0

Notice: with npm install --legacy-peer-deps (1st tree) gives incorrect tree structure and not with npm install (2nd one).

npm install --legacy-peer-deps results in following error on npm run build:

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

I have prepared a repo at https://github.com/developer-73/ajv-peerdep-issue.
I am using following devDependencies ::

"babel-loader": "9.1.2",
"eslint": "8.36.0"

  • eslint@8.36.0 depends on avj@^6.12.4
  • babel-loader@^9.1.2 depends on schema-utils@^4.0.0 which further depends on :
    ajv@^8.8.0 and ajv-keywords@^5.0.0, where ajv-keywords has a peer dependency on ajv@^8.8.0

Run npm install --legacy-peer-deps and notice the incorrect tree structure in node_modules i.e. ajv-keywords@5.1.0
gets hoisted on the root level of node_modules and is using incorrect version of ajv@6.12.6.
This is a problem because the hoisted ajv-keywords@^5.0.0 will not have its peer dependency on ajv@^8.8.0 met.

Note: This works correctly on npm < 7

Possible solution: Can you please add "ajv" as your packages dependencies instead of devDependency? This will ensure "ajv-keywords" to get latest "ajv" version

**Environment**
npm: 8.19.4
Node.js: 18.15.0
OS Name: Mac OS
@developer-73 developer-73 changed the title Add "ajv" as its dependency instead of devDependency Error: Cannot find module 'ajv/dist/compile/codegen' Mar 30, 2023
GuiDevloper added a commit to GuiDevloper/nullstack-adapters that referenced this issue Jun 9, 2023
Remove `ajv` npm dep fix for [this](ajv-validator/ajv-keywords#385) applied today because of TurboCLI used by StackBlitz. Reason: exactly today they deprecated it and opted in using native npm 🤡
@parker-siroishka
Copy link

I seem to be encountering the very same issue you have. Were you able to find a fix for it?

@s100
Copy link

s100 commented Feb 22, 2024

In order to prevent this disagreement at the top level of node_modules, I have found that a workaround is to manually add dependencies on specific, agreeing versions of schema-utils, ajv and ajv-keywords.

So in your package.json under "dependencies" or "devDependencies", try adding either:

"schema-utils": "^3.3.0",
"ajv": "^6.12.6",
"ajv-keywords": "^3.5.2",

or:

"schema-utils": "^4.2.0",
"ajv": "^8.12.0",
"ajv-keywords": "^5.1.0",

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

No branches or pull requests

3 participants