Skip to content

Not valid ESM typings #383

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
Arilas opened this issue May 6, 2025 · 7 comments · Fixed by #384 or #385
Closed

Not valid ESM typings #383

Arilas opened this issue May 6, 2025 · 7 comments · Fixed by #384 or #385
Assignees
Labels
bug Indicates a reported issue or malfunction that needs fixing.
Milestone

Comments

@Arilas
Copy link

Arilas commented May 6, 2025

Your package has single "types" entry in your package.json, you should have something like:

"exports": {
    ".": {
      "import": {
        "types": "./dist/index.d.mts",
        "default": "./src/index.mts"
      },
      "require": {
        "types": "./dist/index.d.ts",
        "default": "./src/index.mts"
      }
    }
  },

Also, your typing information is not valid ESM, because it uses relative imports without extensions, so TypeScript ignores those imports. Example of error:

Image

The easiest fix would be to replace custom rollup config with tsup, and adding format: ['esm', 'cjs'], dts: true to tsup config.

@Arilas
Copy link
Author

Arilas commented May 6, 2025

I've just made a fix in my fork: esm-js@8934d33
You can try it with @esm-js/jira.js:

Image

You've made a change in package.json with type: module, but it made your whole package not completely supported by a native CommonJS runtime, I've reverted it

@MrRefactoring
Copy link
Owner

Hey @Arilas! Can you give an example of when this failed? A playground demo would be ideal

@Arilas
Copy link
Author

Arilas commented May 6, 2025

@MrRefactoring The easiest way is to:

  1. Create a new project
  2. set "type": "module" in package.json.
  3. Init TypeScript
  4. Add jira.js
  5. Set in tsconfig.json:
"module": "Node16"
  1. Create a new file like "index.ts" and add an import like:
import { Version3Client } from 'jira.js'
  1. Observe error from TypeScript.

You can also check the docs about ESM in TypeScript - https://www.typescriptlang.org/tsconfig/#node16node18nodenext
Or from their blog post long ago - https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#esm-nodejs

@Arilas
Copy link
Author

Arilas commented May 6, 2025

@MrRefactoring I've made a very simple demo repository. https://github.com/Arilas/jira-bug-example

You can clone and see the error in IDE or run tsc

@Arilas
Copy link
Author

Arilas commented May 6, 2025

Btw, neighbour issue is related to a type: module in your package.json. It thinks that your package is ESM even when trying to load CommonJS bundle. My fix will also will fix this issue, because you will have a separate entries into package for ESM and CommonJS.

@MrRefactoring MrRefactoring self-assigned this May 6, 2025
@MrRefactoring MrRefactoring added the bug Indicates a reported issue or malfunction that needs fixing. label May 6, 2025
@MrRefactoring MrRefactoring added this to the v5.1.1 milestone May 6, 2025
MrRefactoring added a commit that referenced this issue May 6, 2025
@MrRefactoring
Copy link
Owner

MrRefactoring commented May 6, 2025

@Arilas, could you please test the 5.1.1-dev20250506193213 dev tag?

npm i jira.js@5.1.1-dev20250506193213

MrRefactoring added a commit that referenced this issue May 6, 2025
@MrRefactoring MrRefactoring linked a pull request May 6, 2025 that will close this issue
MrRefactoring added a commit that referenced this issue May 6, 2025
MrRefactoring added a commit that referenced this issue May 7, 2025
@MrRefactoring MrRefactoring mentioned this issue May 7, 2025
@MrRefactoring MrRefactoring linked a pull request May 7, 2025 that will close this issue
@mtughan
Copy link

mtughan commented May 8, 2025

@Arilas, could you please test the 5.1.1-dev20250506193213 dev tag?

npm i jira.js@5.1.1-dev20250506193213

FWIW, I ran across this same issue when I tried out version 5.0.0. The 5.1.1-dev20250506193213 tag fixes it for me and allows me to use ESM typings.

MrRefactoring added a commit that referenced this issue May 8, 2025
* ci improvements, dependencies updated

* #381 commonjs fix (#382)

* #381 commonjs fix

* CHANGELOG added for v5.1.1

* #383 esm fix (#384)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates a reported issue or malfunction that needs fixing.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants