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

Require of @stoplight/spectral-core 1.7.0 fails to error node js 16 #2002

Closed
Havunen opened this issue Dec 15, 2021 · 5 comments
Closed

Require of @stoplight/spectral-core 1.7.0 fails to error node js 16 #2002

Havunen opened this issue Dec 15, 2021 · 5 comments
Labels
wontfix This will not be worked on

Comments

@Havunen
Copy link

Havunen commented Dec 15, 2021

usage:

const { Spectral, isOpenApiv2, isOpenApiv3, mergeRules } = require('@stoplight/spectral-core');

results =>

    Cannot find module 'nimma/legacy' from 'node_modules/@stoplight/spectral-core/dist/runner/runner.js'

    Require stack:
      node_modules/@stoplight/spectral-core/dist/runner/runner.js
      node_modules/@stoplight/spectral-core/dist/runner/index.js
      node_modules/@stoplight/spectral-core/dist/spectral.js
      node_modules/@stoplight/spectral-core/dist/index.js
      src/spectral/utils/spectral-validator.js
      src/cli-validator/utils/validator.js
      src/cli-validator/runValidator.js
      test/cli-validator/tests/error-handling.test.js

      at Resolver.resolveModule (node_modules/jest-resolve/build/resolver.js:324:11)
      at Object.<anonymous> (node_modules/@stoplight/spectral-core/src/runner/runner.ts:9:1)

what is nimma/legacy? .... 😠

@Havunen Havunen changed the title Require of @stoplight/spectral-core fails to error node js 16 Require of @stoplight/spectral-core 1.7.0 fails to error node js 16 Dec 15, 2021
@P0lip
Copy link
Contributor

P0lip commented Dec 15, 2021

It's not an issue with Node.js, but with Jest not understanding package exports
You should either enable ESM support in Jest as explained here or set an appropriate moduleNameMapper, i.e. '^nimma/legacy$': '<rootDir>/node_modules/nimma/dist/legacy/cjs/index.js',

@P0lip P0lip closed this as completed Dec 15, 2021
@P0lip P0lip added the wontfix This will not be worked on label Dec 15, 2021
@tmtron
Copy link

tmtron commented Dec 23, 2021

I also had to map some more modules (when using "ibm-openapi-validator": "0.52.0"):

  moduleNameMapper: {
    '^nimma/legacy$': '<rootDir>/node_modules/nimma/dist/legacy/cjs/index.js',
    '^nimma/(.*)': '<rootDir>/node_modules/nimma/dist/cjs/$1',
    '^@stoplight/spectral-ruleset-bundler/(.*)$': '<rootDir>/node_modules/@stoplight/spectral-ruleset-bundler/dist/$1'
  }

@DavidBiesack
Copy link

I also had to add

    '^nimma/fallbacks$': '<rootDir>/node_modules/nimma/dist/legacy/cjs/fallbacks/index.js'

to get Jest to work with spectral-core

@cb-shivamagarwal
Copy link

Ref - #2167 (comment)

@tmtron
Copy link

tmtron commented Jul 6, 2023

After upgrading to jest 28, we could remove the moduleNameMapper workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

5 participants