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

Problem with ajv package since upgrading to orval 6.6.1 #326

Closed
yekver opened this issue Feb 17, 2022 · 18 comments
Closed

Problem with ajv package since upgrading to orval 6.6.1 #326

yekver opened this issue Feb 17, 2022 · 18 comments

Comments

@yekver
Copy link
Contributor

yekver commented Feb 17, 2022

During the npm install execution I've got these notifications:

npm WARN @stoplight/better-ajv-errors@1.0.1 requires a peer of ajv@>=8 but none is installed. You must install peer dependencies 
yourself.
npm WARN ajv-errors@3.0.0 requires a peer of ajv@^8.0.1 but none is installed. You must install peer dependencies yourself.

Execution of npx orval command fails with an error:

internal/modules/cjs/loader.js:883
  throw err;
  ^

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

Installing the ajv package didn't fix the situation. I just got another error:
Error compiling schema, function code: <LOTS_OF_CODE_HERE>

        throw e;
        ^

SyntaxError: Unexpected token ':'
    at new Function (<anonymous>)
    at Ajv.compileSchema (node_modules\@stoplight\spectral-core\node_modules\ajv\dist\compile\index.js:89:30)
@melloware
Copy link
Collaborator

In your project or just trying to compile Orval ? Orval uses yarn not npm.

However I am using Orval 6.6.1 in my npm project without issue?

@yekver
Copy link
Contributor Author

yekver commented Feb 18, 2022

Yeah, I'm using it on project. Orval v. 6.6.0 works just fine.

However I am using Orval 6.6.1 in my npm project without issue?

You may not have faced with this issue because of different orval configuration

@anymaniax
Copy link
Collaborator

We updated some dependencies maybe that can cause the problem

@anymaniax
Copy link
Collaborator

Could be a problem with the dependency ibm-openapi-validator that use @stoplight/better-ajv-errors

@anymaniax
Copy link
Collaborator

From what I see in the lock file you should have that dependency

@anymaniax
Copy link
Collaborator

which version of npm/node are you using?

@yekver
Copy link
Contributor Author

yekver commented Feb 18, 2022

which version of npm/node are you using?

npm v6.14.12
node v14.16.1

@anymaniax
Copy link
Collaborator

I am not able to reproduce de problem 🙁

@yekver
Copy link
Contributor Author

yekver commented Feb 18, 2022

Maybe that is because of windows environment...

Here is full log:

> npx orval
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'ajv/dist/compile/codegen'
Require stack:
- C:\project\node_modules\ajv-errors\dist\index.js
- C:\project\node_modules\@stoplight\spectral-core\dist\ruleset\validation.js
- C:\project\node_modules\@stoplight\spectral-core\dist\ruleset\ruleset.js
- C:\project\node_modules\@stoplight\spectral-core\dist\spectral.js
- C:\project\node_modules\@stoplight\spectral-core\dist\index.js
- C:\project\node_modules\ibm-openapi-validator\src\spectral\spectral-validator.js
- C:\project\node_modules\ibm-openapi-validator\src\lib\index.js
- C:\project\node_modules\orval\dist\chunk-WXHV4CY3.js
- C:\project\node_modules\orval\dist\bin\orval.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (C:\project\node_modules\ajv-errors\dist\index.js:4:19)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\project\node_modules\\ajv-errors\\dist\\index.js',
    'C:\\project\node_modules\\@stoplight\\spectral-core\\dist\\ruleset\\validation.js',
    'C:\\project\node_modules\\@stoplight\\spectral-core\\dist\\ruleset\\ruleset.js',
    'C:\\project\node_modules\\@stoplight\\spectral-core\\dist\\spectral.js',
    'C:\\project\node_modules\\@stoplight\\spectral-core\\dist\\index.js',
    'C:\\project\node_modules\\ibm-openapi-validator\\src\\spectral\\spectral-validator.js',
    'C:\\project\node_modules\\ibm-openapi-validator\\src\\lib\\index.js',
    'C:\\project\node_modules\\orval\\dist\\chunk-WXHV4CY3.js',
    'C:\\project\node_modules\\orval\\dist\\bin\\orval.js'
  ]
}

@yekver
Copy link
Contributor Author

yekver commented Feb 18, 2022

Seems like this issue is linked to this one and probably caused by bumping up the openapi-validator version from 0.53.1 to 0.55.0

@melloware
Copy link
Collaborator

melloware commented Feb 18, 2022

I am using...

npm: v8.0.0
node: v16.11.0

let us know if you figure it out. Oh also I am using just React Query. My config is pretty straightforward.

module.exports = {
  authorization: {
    output: {
      mode: 'tags',
      target: 'src/service/openapi-auth/authorization.ts',
      client: 'react-query',
      mock: false,
      prettier: true,
      override: {
        useDates: true,
        mutator: {
          path: './src/service/AuthorizationMutator.ts',
          name: 'useAuthAxiosMutator',
        },
        query: {
          useQuery: true,
        }
      }
    },
    input: {
      target: './authorization-openapi.json',
    },
  },
};

@melloware
Copy link
Collaborator

Yep looks like its fixed in 0.56.2 submitting a PR.

melloware added a commit to melloware/orval that referenced this issue Feb 18, 2022
@anymaniax
Copy link
Collaborator

Normally fixed with 6.6.3

@yekver
Copy link
Contributor Author

yekver commented Feb 21, 2022

Looks like the problem is caused by an npm because switching to yarn fixes the probled.

I have this errors by doing the npm ls ajv command:

+-- eslint@8.9.0
| +-- @eslint/eslintrc@1.1.0
| | `-- ajv@6.12.6  deduped
| `-- ajv@6.12.6
+-- fork-ts-checker-webpack-plugin@6.5.0
| `-- schema-utils@2.7.0
|   `-- ajv@6.12.6  deduped
+-- mini-css-extract-plugin@2.5.3
| `-- schema-utils@4.0.0
|   +-- ajv@8.10.0
|   `-- ajv-formats@2.1.1
|     `-- ajv@8.10.0
+-- orval@6.6.3
| `-- ibm-openapi-validator@0.57.0
|   +-- @ibm-cloud/openapi-ruleset@0.6.0
|   | +-- @stoplight/spectral-functions@1.5.1
|   | | `-- UNMET PEER DEPENDENCY ajv@8.10.0
|   | `-- @stoplight/spectral-rulesets@1.4.3
|   |   `-- UNMET PEER DEPENDENCY ajv@8.10.0
|   +-- @stoplight/spectral-cli@6.2.1
|   | `-- @stoplight/spectral-ruleset-migrator@1.7.2
|   |   `-- ajv@8.10.0
|   `-- @stoplight/spectral-core@1.10.1
|     `-- UNMET PEER DEPENDENCY ajv@8.10.0
+-- stylelint@14.5.1
| `-- table@6.8.0
|   `-- ajv@8.10.0
+-- webpack@5.69.1
| +-- schema-utils@3.1.1
| | `-- ajv@6.12.6  deduped
| `-- terser-webpack-plugin@5.3.1
|   `-- schema-utils@3.1.1
|     `-- ajv@6.12.6  deduped
`-- webpack-dev-server@4.7.4
  +-- schema-utils@4.0.0
  | `-- ajv@8.10.0
  `-- webpack-dev-middleware@5.3.1
    `-- schema-utils@4.0.0
      `-- ajv@8.10.0

npm ERR! peer dep missing: ajv@>=8, required by @stoplight/better-ajv-errors@1.0.1
npm ERR! peer dep missing: ajv@^8.0.1, required by ajv-errors@3.0.0
npm ERR! peer dep missing: ajv@>=8, required by @stoplight/better-ajv-errors@1.0.1
npm ERR! peer dep missing: ajv@>=8, required by @stoplight/better-ajv-errors@1.0.1
npm ERR! peer dep missing: ajv@^8.0.1, required by ajv-errors@3.0.0

@anymaniax
Copy link
Collaborator

@yekver
Copy link
Contributor Author

yekver commented Feb 21, 2022

I think we can close this issue in case I have no ability to upgrade npm to v7 and issue can be easily fix by switching to yarn

@yekver yekver changed the title Unable to use orval 6.6.1 Problem with ajv package since upgrading to orval 6.6.1 Feb 21, 2022
@melloware
Copy link
Collaborator

Which explains why I am not seeing it I am on NPM 8.

@yekver
Copy link
Contributor Author

yekver commented Feb 22, 2022

JFYI: running npm i -D ajv && npm dedupe fixes the problem

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

No branches or pull requests

3 participants