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 :
- import * as fs from "node:fs";
- import { fileURLToPath } from "node:url";
- import * as path from "node:path";
- import { join } from "path";
- import { bundleAndLoadRuleset } from "@stoplight/spectral-ruleset-bundler/with-loader";
- //const { bundleAndLoadRuleset } = require("@stoplight/spectral-ruleset-bundler/with-loader");
- import Parsers from "@stoplight/spectral-parsers"; // make sure to install the package if you intend to use default parsers!
- import spectralCore from "@stoplight/spectral-core";
- const { Spectral, Document } = spectralCore;
- import spectralRuntime from "@stoplight/spectral-runtime";
- const { fetch } = spectralRuntime;
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
- //file:///C:/path/
- const myDocument = new Document(
- // 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
- fs.readFileSync(join(__dirname, ".openapi.yaml"), "utf-8").trim(),
- Parsers.Yaml,
- ".openapi.yaml",
- );
- const spectral = new Spectral();
- // load a ruleset file from your project's root directory.
- const rulesetFilepath = path.join(__dirname, ".spectral.yaml");
- console.log(rulesetFilepath);
- spectral.setRuleset(bundleAndLoadRuleset(rulesetFilepath, { fs, fetch }));
- console.log(myDocument);
- spectral.run(myDocument).then(console.log);
Please help
Thanks
AD
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 :
Please help
Thanks
AD