-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 documentation on how to setup eslint-plugin-import with flat confiuration and Typescript #3051
Comments
The PR has some documentation I was trying to follow, but I have not fully resolved it yet (likely a me issue). See #3018 Also, until I properly update to latest versions, I pinned |
cc @michaelfaith it's possible #3018 caused some regressions in eslint-module-utils. |
That's interesting, though, I'm not sure how that PR could have caused and issue with As far as documentation, I can improve on that for sure. @valleywood did you check out the typescript example that I added to the repo with the flat config PR: https://github.com/import-js/eslint-plugin-import/blob/main/examples/flat/eslint.config.mjs |
2.8.2 worked for me. I'll do some more digging into my ESLint config. I was trying to do an "update all" pass and got everything except import plugin updated. I was also running I'll open a separate issue for what I see if needed though. We can keep this focused on documentation if desired? Up to y'all |
@michaelfaith, I am also experiencing the same error here: I cloned your example repo with the flat config and one way I was able to reproduce was by trying to import a third party library. For example:
imports.ts //import c from './exports';
import { a, b } from './exports';
import type { ScalarType, ObjType } from './exports';
import redaxios from 'redaxios';
import path from 'path';
import fs from 'node:fs';
import console from 'console'; Interesting side issue with that project If i dont comment out
|
@michaelfaith Missed that example, thanks! (was looking in the README only) Also notably are that the only packages that are complaining about this in my case are the the Thanks @connorjs for the suggestion to pin Looking forward to a solution though that doesn't require resolution/overrides 🙏 |
I'm experiencing this error, under the rule 'import/namespace', for both imported npm packages and also local pnpm workspace packages I have created. Using typescript, with the settings described in the docs for @typescript-eslint/parser and eslint-import-resolver-typescript. |
This was helpful. For the flat config example in the repo, if you explicitly define a parser for the other configs, then the error goes away. import importPlugin from 'eslint-plugin-import';
import js from '@eslint/js';
import tsParser from '@typescript-eslint/parser';
export default [
js.configs.recommended,
importPlugin.flatConfigs.react,
{
files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
...importPlugin.flatConfigs.recommended,
...importPlugin.flatConfigs.typescript,
languageOptions: {
parser: tsParser,
ecmaVersion: 'latest',
sourceType: 'module',
},
},
{
languageOptions: {
parser: tsParser,
ecmaVersion: 'latest',
sourceType: 'module',
},
ignores: ['eslint.config.mjs', '**/exports-unused.ts'],
rules: {
'no-unused-vars': 'off',
'import/no-dynamic-require': 'warn',
'import/no-nodejs-modules': 'warn',
'import/no-unused-modules': ['warn', { unusedExports: true }],
},
},
]; Which makes me wonder if this is related to what @G-Rath has been experiencing while trying to upgrade the plugin to support v9. They've been getting the same errors while trying to run the unit test suite with v9, and through console logging, found that eslint wasn't putting the default parser (espree) on the context, when a parser wasn't explicitly defined (eslint/eslint#17953 (comment)). So, it could be a bug with eslint, or it could be that the context isn't meant to have the parser attached if the user didn't define a parser, which makes the check that this plugin does in |
Actually, I think I might have figured it out why the parser isn't making it through on the context. I should be able to get a fix in |
This change fixes a bug with flat config support. There is a function called `childContext` that's used by the ExportBuilder to "cleanse" the context object. This function wasn't including the new `languageOptions` object, which contains the parser. So by the time this cleansed context made it to the parse function, `languageOptions` wasn't there anymore. Since `parserPath` was still being included in non-flat config scenarios, the parse function made it through ok and used `parserPath`. However, once you shift to flat config, `parserPath` is no longer defined, and the actual parser object needs to be there. Fixes import-js#3051
@michaelfaith, this seems to get me passed the no parser error! I can go ahead and approve my from standpoint (not sure who officially needs to do it). Would love if this got released soon! |
This change fixes a bug with flat config support. There is a function called `childContext` that's used by the ExportBuilder to "cleanse" the context object. This function wasn't including the new `languageOptions` object, which contains the parser. So by the time this cleansed context made it to the parse function, `languageOptions` wasn't there anymore. Since `parserPath` was still being included in non-flat config scenarios, the parse function made it through ok and used `parserPath`. However, once you shift to flat config, `parserPath` is no longer defined, and the actual parser object needs to be there. Fixes import-js#3051
Thanks for verifying. |
@ljharb, I see this fix was merged in. Is this something that will be released soon? If there's a better spot for me to ask, please let me know |
Yes, but in general asking doesn't do much, so the best thing is to wait :-) |
The version 2.30.0 of `eslint-plugin-import` triggers "parserPath or languageOptions.parser is required!" error (see import-js/eslint-plugin-import#3051)
The version 2.30.0 of `eslint-plugin-import` triggers "parserPath or languageOptions.parser is required!" error (see import-js/eslint-plugin-import#3051)
This change fixes a bug with flat config support. There is a function called `childContext` that's used by the ExportBuilder to "cleanse" the context object. This function wasn't including the new `languageOptions` object, which contains the parser. So by the time this cleansed context made it to the parse function, `languageOptions` wasn't there anymore. Since `parserPath` was still being included in non-flat config scenarios, the parse function made it through ok and used `parserPath`. However, once you shift to flat config, `parserPath` is no longer defined, and the actual parser object needs to be there. Fixes import-js#3051
The version 2.30.0 of `eslint-plugin-import` triggers "parserPath or languageOptions.parser is required!" error (see import-js/eslint-plugin-import#3051)
Readme only contains information about how to setup typescript for this plugin using the old (non-flat) eslint configuration format.
https://github.com/import-js/eslint-plugin-import?tab=readme-ov-file#typescript
Upgraded to latest eslint-plugin-import and now the compat functions from @eslint/compat cant be used any longer (fixupConfigRules/fixupPluginRules) and i don't manage to lint my ts files any longer.
I get loads of errors like this:
I have a languageOptions.parser defined in my config:
The text was updated successfully, but these errors were encountered: