Trying to implement example-2.mjs from spotlight Js code sample -> link

I am using express,node and typescript to implement js api linting. I copied sample example and tried running on vscode in express. Getting following error.

Tried following this -> https://github.com/stoplightio/spectral/issues/2092 where one user had similar issue but he was using commonjs where as I am using ES module.

Added type: module in package.json tried changing extension. that didn' help.

Tried few options by adding export in tsconfig (screenshot below), also in package.json. didn't work out

I think something is off here -> package.json of spectral-ruleset-bundler (screenshot at very bottom)

enter image description here

Package.json -> enter image description here

tsconfig.json -> enter image description here

enter image description here

2

There are 2 best solutions below

0
On BEST ANSWER

Changed noduleResolution from node to node16 and it worked without any modification to spectral-ruleset-bundler package.json

enter image description here

0
On

found this demo code -> https://github.com/tylerlong/spectral-demo/blob/main/README.md

It is mentioned in the know issue section

workaround: delete exports from package.json and import {xxx} from @stoplight/spectral-ruleset-bundler/dist/loader/node

after deleting following and adding this on top of the ts file -> import { bundleAndLoadRuleset } from '@stoplight/spectral-ruleset-bundler/dist/loader/node.js';

it worked!!

removing something from package's package.json doesn't seem good solution.

enter image description here