ajv-validator / ajv-draft-04

Ajv JSON validator for JSON Schema draft-04
MIT License
10 stars 3 forks source link

Error while using ajv-draft-04: Cannot find module ajv/dist/core #4

Closed umeshp7 closed 2 years ago

umeshp7 commented 2 years ago

Receiving the following error when using this module:

Error: Cannot find module 'ajv/dist/core' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15) at Function.Module._load (internal/modules/cjs/loader.js:562:25) at Module.require (internal/modules/cjs/loader.js:692:17) at require (internal/modules/cjs/helpers.js:25:18) _at Object. (nodemodules/ajv-draft-04/dist/index.js:4:16) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:692:17) at require (internal/modules/cjs/helpers.js:25:18) at Object. (node_modules/openapi-to-postmanv2/lib/ajValidation/ajvValidatorDraft04.js:1:13) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:692:17) at require (internal/modules/cjs/helpers.js:25:18) at Object. (node_modules/openapi-to-postmanv2/lib/ajValidation/ajvValidation.js:6:34) at Module._compile (internal/modules/cjs/loader.js:778:30)

Check the highlighter line in the error.

r3pps commented 2 years ago

@umeshp7 how did you resolve this?

netpoetica commented 2 years ago

I receive this error immediately when trying to utilize this package. Did anyone ever resolve this?

What version of ajv should be used in conjunction with this lib, ajv@6 per their docs, or the newest one?

$ node -v
v14.15.4

$ npm -v
6.14.10

$ npm ls ajv
-- ajv@6.12.6

$ npm ls ajv-draft-04
-- ajv-draft-04@1.0.0
nfroidure commented 2 years ago

For the record, I solved this using NPM overrides:

{
  "overrides": {
    "openapi-ts-sdk-builder": {
      "@apidevtools/swagger-parser": {
        "ajv": "8.5.0"
      }
    }
  }
}

Beware that since ajv is a peer dependency of ajv-draft-04, you have to find the dependency that uses it to override, in my case openapi-ts-sdk-builder.To find it just use npm list ajv.

mems commented 1 year ago

FYI: I've got the same issue:

Cannot find module 'ajv/dist/core'
Require stack:
- /builds/fnacdarty/fdps/dev/teams/fnacproduit/adobe-launch-fnac-web-extension/node_modules/ajv-draft-04/dist/index.js
- /builds/fnacdarty/fdps/dev/teams/fnacproduit/adobe-launch-fnac-web-extension/node_modules/@adobe/reactor-validator/lib/index.js
- /builds/fnacdarty/fdps/dev/teams/fnacproduit/adobe-launch-fnac-web-extension/node_modules/@adobe/reactor-packager/tasks/index.js

And I fix it by using node 16 instead of node 14