hyperjump-io / json-schema

JSON Schema Validation, Annotation, and Bundling. Supports Draft 04, 06, 07, 2019-09, 2020-12, OpenAPI 3.0, and OpenAPI 3.1
https://json-schema.hyperjump.io/
MIT License
224 stars 21 forks source link

Typescript error while importing from `@hyperjump/json-schema/experimental` #38

Closed GabenGar closed 1 year ago

GabenGar commented 1 year ago

When building I get this error:

error TS2307: Cannot find module '@hyperjump/json-schema/experimental' or its corresponding type declarations.

Reproduction:

git clone https://github.com/GabenGar/repros
cd ./repros/json-schema-experimental-module
npm install
npm run build

It is an issue with type definitions because vanilla js file works fine.

jdesrosiers commented 1 year ago

This package uses the package.json "exports" field. TypeScript understands "exports", but you need to change a couple settings in your tsconfig.json for it to work.

    "module": "Node16",
    "moduleResolution": "Node16",

or

    "module": "NodeNext",
    "moduleResolution": "NodeNext",

This is probably something that would be helpful to add to the README.

GabenGar commented 1 year ago

Okay, I've tried with these options and it does work. The issue however is I encountered the problem while working on a Next.js project and afaik it has some problems consuming "true" ESM code, so switching these flags is not so trivial. But it' not a problem of this package.