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

Bug: ReferenceError: Cannot access 'plugin' before initialization #20

Closed
zollipaul opened this issue Dec 3, 2024 · 1 comment
Closed

Comments

@zollipaul
Copy link

When manually configuring the plugin, i get an error after running npx eslint.

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
// this import is causing the error
import typeormTypescriptPlugin from 'eslint-plugin-typeorm-typescript'; 

export default tseslint.config(
  eslint.configs.recommended,
  ...tseslint.configs.recommended,
  {
    plugins: {'typeorm-typescript': typeormTypescriptPlugin},
    rules: {
      "typeorm-typescript/enforce-column-types": "error",
      "typeorm-typescript/enforce-relation-types": "warn",
      "typeorm-typescript/enforce-consistent-nullability": ["error", { "specifyNullable": "always" }]
    }
  }
);

Error:

Oops! Something went wrong! :(

ESLint: 9.16.0

ReferenceError: Cannot access 'plugin' before initialization
    at file:///Users/******/app/node_modules/eslint-plugin-typeorm-typescript/es/recommended.js:4:31

But this works:

import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import typeormTypescriptPlugin from 'eslint-plugin-typeorm-typescript';

export default tseslint.config(
  eslint.configs.recommended,
  ...tseslint.configs.recommended,
  {
    plugins: {'typeorm-typescript': typeormTypescriptPlugin},
    rules: {
      "typeorm-typescript/enforce-column-types": "error",
      "typeorm-typescript/enforce-relation-types": "warn",
      "typeorm-typescript/enforce-consistent-nullability": ["error", { "specifyNullable": "always" }]
    }
  }
);
@daniel7grant
Copy link
Owner

Thanks for your issue, it is absolutely correct, there was a circular dependency between the main plugin and recommended exports, which made ES Modules break. I already planned a release (v0.5.0), and I added a fix which should solve this issue, as well as an example which tests if the customization breaks. Feel free to test with the new version, and reopen if you still have problems.

Thanks for your help!

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