Skip to content

Version 3 isn't esm friendly anymore #50

@OlivierCuyp

Description

@OlivierCuyp

With previous the version 2, I had no issue using this package with tsx or ts-node targeting esm.
Now with version 3, convert is not a function but an object with a default key containing the function.
Here is what I mean:

Convert2: [AsyncFunction: convert]
Convert3: { default: [AsyncFunction: convert] }

Below the steps to reproduce in Node v20.11.1.

Install:

npm init -y
npm i -D tsx ts-node
npm i json-schema-to-openapi-schema2@npm:@openapi-contrib/json-schema-to-openapi-schema@2 \
          json-schema-to-openapi-schema3@npm:@openapi-contrib/json-schema-to-openapi-schema@3 \

package.json:

{
  // ...
  "type": "module",
  // ...
}

test.ts:

import convert2 from 'json-schema-to-openapi-schema2';
import convert3 from 'json-schema-to-openapi-schema3';

console.log('Convert2:', convert2);
console.log('Convert3:', convert3);

tscong.json:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "alwaysStrict": true
  }
}

Run with tsx:

npx tsx ts-node/esm index.ts

Run with ts-node:

node --loader ts-node/esm index.ts

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