Skip to content
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

Missing "import" key in package.json exports for ESM compatibility #38

Closed
Vorathe opened this issue Jan 3, 2025 · 7 comments · Fixed by #51
Closed

Missing "import" key in package.json exports for ESM compatibility #38

Vorathe opened this issue Jan 3, 2025 · 7 comments · Fixed by #51
Labels
bug Something isn't working

Comments

@Vorathe
Copy link

Vorathe commented Jan 3, 2025

Describe the bug
Upgraded to 1.0.12 from 1.0.9 and after running eslint with this update, I see the following error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /node_modules/@smarttools/eslint-plugin-rxjs/package.json imported from /eslint.config.mjs

Repro
Version of @smarttools/eslint-plugin-rxjs you are using: 1.0.12

  1. Create a ESM compatible eslint config
  2. Import '@smarttools/eslint-plugin-rxjs' and add it to plugins and add recommended rules
  3. Run eslint against any file
  4. See error above

Repository that has a reproduction of the problem: Private

Additional context
Downgrading to @smarttools/[email protected] resolves the issue for my project.

Adding "import": "./index.cjs", to the exports in package.json#33 fixes the issue in 1.0.12 for ESM based configs:

"exports": { ".": { "require": "./index.cjs", "import": "./index.cjs", "types": "./index.d.ts" } }

@Vorathe Vorathe added the bug Something isn't working label Jan 3, 2025
@Vorathe Vorathe changed the title Missing "import" key in package.json exports Missing "import" key in package.json exports for ESM compatibility Jan 3, 2025
@DaveMBush
Copy link
Owner

A sample project would be helpful.

@amikheychik
Copy link

@DaveMBush the bug report has a correct suggestion.

CommonJS file can be imported into ES modules. But as you explicitly set exports for require, you also have to explicitly set "import": "./index.cjs" (or remove the whole exports block).

Variant A:

{
  "name": "@smarttools/eslint-plugin-rxjs",
  
  "type": "commonjs",
  "main": "./index.cjs",
  "types": "./index.d.ts"
}

Variant B:

{
  "name": "@smarttools/eslint-plugin-rxjs",

  "type": "commonjs",
  "main": "./index.cjs",
  "types": "./index.d.ts",
  "module": "./index.cjs",
  "exports": {
    ".": {
      "require": "./index.cjs",
      "types": "./index.d.ts",
       "import": "./index.cjs"
    }
  }
}

@DaveMBush
Copy link
Owner

Yes, and thank you.

The reason I want a project that exhibits the problem is so I have something I can test the change against, at least manually, so I can prove to myself that the change fixes the problem and so that the problem does not show up in the future.

@amikheychik
Copy link

@DaveMBush
Copy link
Owner

Thank you so much

@rubiesonthesky
Copy link

https://arethetypeswrong.github.io/?p=%40smarttools%2Feslint-plugin-rxjs%401.0.13 highlights some problem that kinda works right now but relies on Typescript bug, if I understood correctly.

--

I have this same problem on versions > 1.0.8

Minimalish eslint config file: eslint.config.mjs

import rxjs from '@smarttools/eslint-plugin-rxjs';
import tseslint from 'typescript-eslint';

export default tseslint.config(
  {
    plugins: {
      '@typescript-eslint': tseslint.plugin,
      rxjs,
    },
  },
  {
    files: ['**/*.ts'],
    extends: [
      rxjs.configs.recommended,
    ],
  },
);

@DaveMBush
Copy link
Owner

This should be fixed in 1.0.14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants