Skip to content

When not installing globally: Cannot find module 'ajv/dist/compile/codegen' #2162

@thany

Description

@thany

This error doesn't happen when installing orval globally and calling it straight away. This error only happens when installing orval like this:

npm i -D orval

And then executing it through an npm script in the package.json:

{
  "scripts": {
    "openapi": "orval --config orval.config.ts"
  },
  // ...
}

Full error:

>npm run openapi

> @renewi/[email protected] openapi
> orval --config orval.config.ts

node:internal/modules/cjs/loader:1404
  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\ajv.js
- C:\Project\node_modules\@stoplight\spectral-core\dist\ruleset\validation\assertions.js
- C:\Project\node_modules\@stoplight\spectral-core\dist\ruleset\validation\index.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\@stoplight\spectral-functions\dist\alphabetical.js
- C:\Project\node_modules\@stoplight\spectral-functions\dist\index.js
- C:\Project\node_modules\@stoplight\spectral-rulesets\dist\oas\index.js
- C:\Project\node_modules\@stoplight\spectral-rulesets\dist\index.js
- C:\Project\node_modules\@ibm-cloud\openapi-ruleset\src\ibm-oas.js
- C:\Project\node_modules\@orval\core\dist\index.js
- C:\Project\node_modules\orval\dist\bin\orval.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1401:15)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1057:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1062:22)
    at Function._load (node:internal/modules/cjs/loader:1211:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:235:24)
    at Module.require (node:internal/modules/cjs/loader:1487:12)
    at require (node:internal/modules/helpers:135:16)
    at Object.<anonymous> (C:\Project\node_modules\ajv-errors\dist\index.js:4:19)
    at Module._compile (node:internal/modules/cjs/loader:1730:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'C:\\Project\\node_modules\\ajv-errors\\dist\\index.js',
    'C:\\Project\\node_modules\\@stoplight\\spectral-core\\dist\\ruleset\\validation\\ajv.js',
    'C:\\Project\\node_modules\\@stoplight\\spectral-core\\dist\\ruleset\\validation\\assertions.js',
    'C:\\Project\\node_modules\\@stoplight\\spectral-core\\dist\\ruleset\\validation\\index.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\\@stoplight\\spectral-functions\\dist\\alphabetical.js',
    'C:\\Project\\node_modules\\@stoplight\\spectral-functions\\dist\\index.js',
    'C:\\Project\\node_modules\\@stoplight\\spectral-rulesets\\dist\\oas\\index.js',
    'C:\\Project\\node_modules\\@stoplight\\spectral-rulesets\\dist\\index.js',
    'C:\\Project\\node_modules\\@ibm-cloud\\openapi-ruleset\\src\\ibm-oas.js',
    'C:\\Project\\node_modules\\@orval\\core\\dist\\index.js',
    'C:\\Project\\node_modules\\orval\\dist\\bin\\orval.js'
  ]
}

Node.js version: 22.16.0
NPM version: 11.4.2

We have a policy that all neccesary packages for a project must be installed with a simple npm i, which makes a lot of sense to me. Until there's a solution, if there's a workaround that doesn't require a global install, I'm all ears 🙏🏻

Btw, this problem looks a bit like issue #326, but that was an old one, and I'm not sure it's totally identical. Either way, it may be related.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions