ThomasAribart / json-schema-to-ts

Infer TS types from JSON schemas 📝
MIT License
1.47k stars 31 forks source link

tsc compiled js still imports json-schema-to-ts which imports as a "ts" file #39

Closed djvs closed 2 years ago

djvs commented 3 years ago

I notice every other library in my node_modules has "main": "index.js" or similar, and import correctly in my project here.

Maybe you could have that file be a no-op in your published packages, and have "main": "index.js" pointing to that no-op, and "typings": "./lib/index.d.ts" instead, so that imports of 'json-schema-to-ts' don't start throwing errors like:

import { JSONSchema6Definition } from "json-schema";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:979:16)
    at Module._compile (internal/modules/cjs/loader.js:1027:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (./dist/src/myfile.js:21:29)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)

There may be a better way here, I'm not the leading expert on JS module resolution.

ThomasAribart commented 2 years ago

Hi @djvs ! Should be fixed since 2.1.0 🙌 Can you confirm ?