Skip to content

TypeError: Cannot destructure property 'Spectral' of 'spectral_core_1.default' as it is undefined. #2421

Description

@AmitDhingra134

When I am trying to integrate spiral stoplightio in a javascript application in VS code then its showing me below error on line number 9:

TypeError: Cannot destructure property 'Spectral' of 'spectral_core_1.default' as it is undefined.

Code :

  1. import * as fs from "node:fs";
  2. import { fileURLToPath } from "node:url";
  3. import * as path from "node:path";
  4. import { join } from "path";
  5. import { bundleAndLoadRuleset } from "@stoplight/spectral-ruleset-bundler/with-loader";
  6. //const { bundleAndLoadRuleset } = require("@stoplight/spectral-ruleset-bundler/with-loader");
  7. import Parsers from "@stoplight/spectral-parsers"; // make sure to install the package if you intend to use default parsers!
  8. import spectralCore from "@stoplight/spectral-core";
  9. const { Spectral, Document } = spectralCore;
  10. import spectralRuntime from "@stoplight/spectral-runtime";
  11. const { fetch } = spectralRuntime;
  12. const __dirname = path.dirname(fileURLToPath(import.meta.url));
  13. //file:///C:/path/
  14. const myDocument = new Document(
  15. // load an API specification file from your project's root directory. You can use the openapi.yaml example from here: https://github.com/stoplightio/Public-APIs/blob/master/reference/plaid/openapi.yaml
  16. fs.readFileSync(join(__dirname, ".openapi.yaml"), "utf-8").trim(),
  17. Parsers.Yaml,
  18. ".openapi.yaml",
  19. );
  20. const spectral = new Spectral();
  21. // load a ruleset file from your project's root directory.
  22. const rulesetFilepath = path.join(__dirname, ".spectral.yaml");
  23. console.log(rulesetFilepath);
  24. spectral.setRuleset(bundleAndLoadRuleset(rulesetFilepath, { fs, fetch }));
  25. console.log(myDocument);
  26. spectral.run(myDocument).then(console.log);

Please help

Thanks
AD

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions