Skip to content

Version 3 isn't esm friendly anymore #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
OlivierCuyp opened this issue Jun 30, 2024 · 3 comments
Closed

Version 3 isn't esm friendly anymore #50

OlivierCuyp opened this issue Jun 30, 2024 · 3 comments

Comments

@OlivierCuyp
Copy link

OlivierCuyp commented Jun 30, 2024

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
@yehudiduhey
Copy link

Facing the same issue, I don't understand why the transpilation to esm and commonjs was replaced by a transpilation that targets ESM but that uses module commonjs. In my opinion the code should be using ESM modules as it's the new standard. And optionally could still have a commonjs transpiled version as it was setup previously.

@javierlinked
Copy link

javierlinked commented Nov 19, 2024

I cleaned up shortly project transpilation and created this PR to restore ESM.
I had to downgrade in my local project to build v2.2.6 in the meanwhile.

Not sure who is owning this project actually. @jonluca ?

@jonluca
Copy link
Member

jonluca commented Nov 19, 2024

Thanks for the PR! Merged in

@jonluca jonluca closed this as completed Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants