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

Key "plugins": Key "react-refresh": Expected an object. #50

Closed
reyhankaplan opened this issue Sep 13, 2024 · 5 comments
Closed

Key "plugins": Key "react-refresh": Expected an object. #50

reyhankaplan opened this issue Sep 13, 2024 · 5 comments

Comments

@reyhankaplan
Copy link

Hello, I am getting this error when I run the lint command:

ConfigError: Config (unnamed): Key "plugins": Key "react-refresh": Expected an object.

I am using eslint@9.10.0 and I have type="module" in my package.json, I import and use the plugin like this:

import reactRefresh from 'eslint-plugin-react-refresh'
  // ...
  {
    files: ['**/*.tsx'],
    plugins: {
      'react-refresh': reactRefresh,
    },
    rules: {
      'react-refresh/only-export-components': [
        'warn',
        { allowConstantExport: true },
      ],
    },
  },
  // ...

I found that it works fine if I remove the 0 && from the below code in the bundled index.js file or if I use require('eslint-plugin-react-refresh')

// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  rules
});
@ArnaudBarre
Copy link
Owner

What's your node version? Do have any issues when running a fresh vite react templates (also using esm + eslint v9 + this plugin)

@reyhankaplan
Copy link
Author

@ArnaudBarre thank you for your quick response. I figured out that reactRefresh was undefined because the package doesn’t have a default export. It seems like the plugin is developed with Vite in mind, which uses "moduleResolution": "bundler" in its tsconfig.json, this setting automatically makes "allowSyntheticDefaultImports": true by default. It was false in my case, so I had to import the package like this:

import * as reactRefresh from 'eslint-plugin-react-refresh';

Feel free to close this issue as it is resolved on my end. I think the documentation can be updated to reflect this situation or default export can be used when exporting the rules.

@ArnaudBarre
Copy link
Owner

ArnaudBarre commented Sep 13, 2024

Do you have more information on your setup? tsconfig option should only impact how the TS import are resolved for type checking, but it doesn't impact node at runtime, except if you are using something else?

@reyhankaplan
Copy link
Author

Sorry my bad, I am using unstable eslint.config.ts

You can check this repo I created.

Or you can reproduce the issue using Vite with additional eslint.config.ts setup:

  • create a new react-ts vite app npm create vite@latest -- --template react-ts
  • rename eslint.config.js to eslint.config.ts
  • install jiti npm install -D jiti
  • run eslint npx eslint --flag unstable_ts_config.

--

What's your node version?

My node version is 20.16.0

@ArnaudBarre
Copy link
Owner

This is fixed in the latest version!

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

2 participants