Resolve error typescript with invalid interface loaded as resolver

I'm having ESLint in my project and getting an error Resolve Error: typescript with invalid interface loaded as resolver : import-no-restricted-paths when I add the rule import/no-restricted-paths

I’m having ESLint in my project and getting an error Resolve Error: typescript with invalid interface loaded as resolver : import-no-restricted-paths when I add the rule import/no-restricted-paths

Error

tsconfig.json

{
    "include": [
        "./src/**/*",
        "./generated/**/*"
    ],
    "compilerOptions": {
        "resolveJsonModule": true,
        "target": "es5",
        "module": "esnext",
        "moduleResolution": "node",
        "lib": [
            "dom",
            "es6"
        ],
        "downlevelIteration": true,
        "jsx": "react",
        "declaration": false,
        "sourceMap": true,
        "baseUrl": "src",
        "outDir": "./dist/js",
        "paths": {
            "@generated/*": ["../generated/*"],
            "api": ["lib/api"],
            "api/*": ["lib/api/*"],
            "asset/*": ["lib/asset/*"],
            "base/*": ["lib/base/*"]
        },
        // Rules
        "noImplicitAny": false,
        "strictNullChecks": true,
        "noImplicitThis": true,
        "alwaysStrict": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "forceConsistentCasingInFileNames": true,
        "esModuleInterop": true,
        "isolatedModules": true
    }
}

.eslint.json

module.exports = {
    env: {
        browser: true
    },
    settings: {
        "import/parsers": {
            "@typescript-eslint/parser": [".ts", ".tsx"]
        },
        "import/resolver": {
            "typescript": {
                paths: "./tsconfig.json",
                alwaysTryTypes: true
            }
        },
    },
    parser: "@typescript-eslint/parser",
    parserOptions: {
        tsconfigRootDir: ".",
        sourceType: "module",
        project: "./tsconfig.json"
    },
    extends: [
        "plugin:import/recommended",
        "plugin:import/typescript"
    ],
    plugins: [
        "@typescript-eslint",
        "import"
    ],
    overrides: [
        {
            files: [
                "src/_migration/**"
            ],
            rules: {
                "import/no-restricted-paths": [
                    "error",
                    {
                        basePath: "./src",
                        zones: [
                            { target: "./_migration", from: "./", except: ['./_migration'] }
                        ],
                    },
                ]
            }
        },
    ],
    rules: {
        "import/no-unresolved": "off",
        "@typescript-eslint/typedef": [
            "error",
            {
                parameter: true
            }
        ]
    }
};

Содержание

  1. [Regression] eslint-module-utils@2.3.0 causes invalid «Resolve error: webpack with invalid interface loaded as resolver» #1269
  2. Comments
  3. TypeScript With Invalid Interface Loaded As Resolver
  4. Ver 3.2.2 Resolve error: typescript with invalid interface loaded as resolver about eslint-import-resolver-typescript HOT 1 CLOSED
  5. Comments (1)
  6. Related Issues (20)
  7. Recommend Projects
  8. React
  9. Vue.js
  10. Typescript
  11. TensorFlow
  12. Django
  13. Laravel
  14. Recommend Topics
  15. javascript
  16. server
  17. Machine learning
  18. Visualization
  19. Recommend Org
  20. Facebook
  21. Microsoft
  22. Вложенный псевдоним TS Config для абсолютного пути не работает
  23. 4 ответа
  24. Resolve error typescript with invalid interface loaded as resolver
  25. Why this library?
  26. Proposed solution
  27. Awaiting Schedule

[Regression] eslint-module-utils@2.3.0 causes invalid «Resolve error: webpack with invalid interface loaded as resolver» #1269

See minimal reproduction case with script and pre-run output at ronjouch/repro-eslint-bug-cra .

As demonstrated by the demo script, reverting to 2.2.0 inside eslint-plugin-import ( cd node_modules/eslint-plugin-import && npm install eslint-module-utils@2.2.0 ) fixes the issue.

Reproduced and fixed on many machines (node 10.15.0 & npm 6.7.0 on Linux, node 8 on macOS, and in a CI Docker). I’m available for more debug info if necessary.

The text was updated successfully, but these errors were encountered:

@ronjouch what version of eslint-import-resolver-webpack are you using? I don’t see it referenced in either the package-lock.json or the package.json .

what version of eslint-import-resolver-webpack are you using? I don’t see it referenced in either the package-lock.json or the package.json .

@benmosher thanks for the fast reply 👍 . Uh, from what I understand, I’m not using eslint-import-resolver-webpack , neither in the minimal scenario, nor in the production web app I extracted it from.

Here’s an npm ls | grep eslint for the production web app:

Does that make sense to not depend on eslint-import-resolver-webpack ? Did we miss migration steps at some point? Should I add it as dependency? If so, is new configuration needed?

Note: all that stuff is pretty obscure to me, so sorry for the noise. I just happen to be the engineer at $WORK most comfortable narrowing down on the broken package to make our build pass again. My point of view is simple: 2.3.0 broke the build and pinning 2.2.0 fixes it. Is this a regression, or was it already ineffective/useless and it just started being vocal about it?

Sounds like it was silently failing over to the node resolver before. Makes sense it would look like a regression 🙂

If you don’t have the webpack resolver installed, you have two solid options:

  • remove this block from your package.json:
  • install eslint-import-resolver-webpack and see if that works better.

The former is fewer dependencies so I’d try that first, but up to you. Is a little strange you’d end up with the config pointing to it without it in your dependencies.

@benmosher makes sense! Removing the settings block worked 🙂 (and happily started complaining about errors accumulated over the last months 😄 ).

Is a little strange you’d end up with the config pointing to it without it in your dependencies.

Yup, traced to a bad initial commit copy-pastaed / badly adjusted from an example.

Источник

TypeScript With Invalid Interface Loaded As Resolver

TypeScript uses an invalid interface to load itself. This type of error is often associated with the use of a language that is not compatible with it. It can occur in a program using the NodeJS programming language or in any other programming language. It can also occur in a script written in another language. In this article, we will discuss the problem and offer some possible solutions. The first step in the resolution of this error is to find the exact cause of this problem.

This error occurs when a library contains an outdated typescript version. If the error is caused by an older version of the language, you may want to upgrade your browser. This will help you fix the problem in the future. In the meantime, here are some methods you can use to avoid this problem: (1) VSCode’s format on save feature. (2) Prettier, eslint, and Husky.

If you’re using a browser that doesn’t support TypeScript, you might want to upgrade. In particular, try using Firefox’s watch mode. This mode caches the files it needs, and prevents it from being downloaded to your computer. This method is not supported by older versions of this browser. Instead, update your browser to the latest stable version to fix the issue. You can also try a different type of browser, such as Chrome or Firefox.

As an alternative to eslint, you can also use prettier or VSCode’s format on save feature. Alternatively, you can use a scripting tool like Husky to run your Git commands. This method may be time consuming and may not be appropriate for your project. Aside from this, some projects don’t require typescript code checking. This method is not suitable for all types of code.

Using watch mode allows you to avoid this error and keep a clean code structure. In addition, this option makes it easier to maintain code in an OO environment, because every file access will be cached. And every time you need to perform a file operation, you can set a cache before you execute. And when you’re done, you’ll get a stack trace of the entire project.

To resolve this error, you can either use a different type of interface or use a watch mode. This mode will allow you to configure the interface of your application and prevent it from crashing. If you have two different interfaces, you can simply rename the files. But if you’d rather have a single, then watch mode is the best option. With this method, you can create a new class based on your existing one.

To resolve this error, use watch mode. The watch mode will let you use watch mode. This mode will enable you to create a nested tree of promises. As a result, a single promise will be loaded with every other one. A chain of promises is an arbitrary set of objects. A single resolution will always cause the other to crash. This method will be asynchronous, but it will allow you to work with it without a break.

You can use watch mode to prevent this error. It will automatically purge the cache of files that are modified. When you use watch mode, you should not worry about the old version of the browser as it will not be affected. This is because the watch mode will prevent the code from being corrupted. It will prevent errors from occurring if it isn’t working in the same way as the previous one.

To resolve this error, use VSCode. Its format on save feature will make your code more readable. You can also use eslint, prettier, and Husky to run your Git commands. But this process will take some time, and some projects might not need it. Then, you can try other solutions that are more efficient. When you need more time to check your code, you can check the code with VSCode.

Источник

Ver 3.2.2 Resolve error: typescript with invalid interface loaded as resolver about eslint-import-resolver-typescript HOT 1 CLOSED

  • feat: add `externsionAlias` option
  • docs: document `enhanced-resolve` options
  • [HELP] Can not get plugin to work with path aliases HOT 7
  • feat: better cache support via hashobject for example HOT 7
  • import/resolver with rules from import/errors and using @typescript-esint/parser causes VSCode to hang while saving files HOT 5
  • synckit dependency breaks usage of this plugin with Yarn PnP in VSCode HOT 1
  • try `resolve.exports`
  • Incorrect path resolved when monorepo project contains multiple tsconfig.json HOT 1
  • not working with js files HOT 2
  • Performance degradation since version 3.1.0 HOT 1
  • Adapt `get-tsconfig`’s `TsConfigJsonResolved` to TypeScript’s `ParsedCommandLine`
  • `no-cycle` not working with import resolver HOT 3
  • statSync without `throwIfNoEntry: false` causes great performance impact when processing typescript imports HOT 4
  • question: resolution order of `project` HOT 1
  • Invitation to move to official `eslint-community` org HOT 4
  • iconv-lite not found in imported namespace HOT 6
  • «Unable to resolve path to module» in monorepo, after Angular 13 upgrade HOT 7
  • Typescript NodeNext path alias with extension HOT 3
  • Incorrect «engines» declaration — not actually working with node 12 HOT 1
  • declare module and import/no-unresolved HOT 1

Recommend Projects

React

A declarative, efficient, and flexible JavaScript library for building user interfaces.

Vue.js

🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

Typescript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

TensorFlow

An Open Source Machine Learning Framework for Everyone

Django

The Web framework for perfectionists with deadlines.

Laravel

A PHP framework for web artisans

Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

javascript

JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

Some thing interesting about web. New door for the world.

server

A server is a program made to process requests and deliver data to clients.

Machine learning

Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

Visualization

Some thing interesting about visualization, use data art

Some thing interesting about game, make everyone happy.

Recommend Org

Facebook

We are working to build community through open source technology. NB: members must have two-factor auth.

Microsoft

Open source projects and samples from Microsoft.

Источник

Вложенный псевдоним TS Config для абсолютного пути не работает

Я пытаюсь настроить псевдонимы путей в моем tsconfig.json для приложения React в комплекте с Vite. Вот соответствующая часть моего tsconfig.json :

Единственная проблема связана с NestedFolder . Когда я импортирую таким образом, все работает:

Однако вложенный псевдоним не работает:

Я хотел бы сделать вложенные компоненты, потому что у меня есть несколько папок, которые вложены 3-4 уровня, и было бы неплохо иметь более четкое представление о моем импорте. Есть ли способ сделать это?

4 ответа

Вам необходимо установить плагин vite-tsconfig-paths для настройки псевдонимов путей. используя TypeScript и Vite. Если ничего не изменилось и вы используете VSCode, обязательно перезапустите сервер TypeScript, нажав Ctrl+Shift+P или Cmd+Shift+P , введя restart , а затем выбрав команду: TypeScript: Restart TS server

Принятый ответ не сработал для меня. Я обнаружил, что мне нужно установить следующие пакеты:

npm i eslint-plugin-import eslint-import-resolver-alias eslint-import-resolver-typescript

Затем добавьте следующие конфигурации, важным компонентом которых являются строго определенные пути псевдонимов:

Я думаю, что это можно улучшить, согласовав псевдонимы между .eslintrc и vite.config, поэтому псевдонимы нужно определять только один раз, используя тактику, подобную той, что определена здесь: https://stackoverflow.com/a/68908814/14198287

Если vite-tsconfig-paths не работает. Убедитесь, что вы не установили v4.0.0 . В этой версии есть ошибка.

Источник

Resolve error typescript with invalid interface loaded as resolver

When a path includes # , it seems that enhanced-resolve replaces it with # (https://github.com/webpack/enhanced-resolve#escaping). Unfortunately further up this causes a failure in eslint-plugin-import :

Why this library?

I could report this to enhanced-resolve , but their escape seems to be well documented and by design. Happy to report there if you think that’s the best option.

I could report this to eslint-plugin-import , however the problem depends on details resolver implementation, and eslint-plugin-import seems resolver-agnostic.

Proposed solution

Path returned by enhanced-resolve can be post-processed to replace # with # , which is the correct representation of the filesystem path.

Created at 19 hours ago

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • chore(deps): update dependency size-limit to ^8.1.1
  • fix(deps): update dependency globby to ^13.1.3
  • chore(deps): update dependency @changesets/cli to ^2.26.0
  • chore(deps): update dependency prettier to ^2.8.3
  • chore(deps): update dependency size-limit-preset-node-lib to ^0.2.0
  • chore(deps): update dependency type-coverage to ^2.24.1
  • chore(deps): update dependency typescript to ^4.9.4
  • chore(deps): update pnpm to v7.25.0
  • fix(deps): update dependency enhanced-resolve to ^5.12.0
  • fix(deps): update dependency get-tsconfig to ^4.3.0
  • fix(deps): update dependency is-core-module to ^2.11.0

Источник

I’m having ESLint in my project and getting an error Resolve Error: typescript with invalid interface loaded as resolver : import-no-restricted-paths when I add the rule import/no-restricted-paths

Error

tsconfig.json

{
    "include": [
        "./src/**/*",
        "./generated/**/*"
    ],
    "compilerOptions": {
        "resolveJsonModule": true,
        "target": "es5",
        "module": "esnext",
        "moduleResolution": "node",
        "lib": [
            "dom",
            "es6"
        ],
        "downlevelIteration": true,
        "jsx": "react",
        "declaration": false,
        "sourceMap": true,
        "baseUrl": "src",
        "outDir": "./dist/js",
        "paths": {
            "@generated/*": ["../generated/*"],
            "api": ["lib/api"],
            "api/*": ["lib/api/*"],
            "asset/*": ["lib/asset/*"],
            "base/*": ["lib/base/*"]
        },
        // Rules
        "noImplicitAny": false,
        "strictNullChecks": true,
        "noImplicitThis": true,
        "alwaysStrict": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "forceConsistentCasingInFileNames": true,
        "esModuleInterop": true,
        "isolatedModules": true
    }
}

.eslint.json

module.exports = {
    env: {
        browser: true
    },
    settings: {
        "import/parsers": {
            "@typescript-eslint/parser": [".ts", ".tsx"]
        },
        "import/resolver": {
            "typescript": {
                paths: "./tsconfig.json",
                alwaysTryTypes: true
            }
        },
    },
    parser: "@typescript-eslint/parser",
    parserOptions: {
        tsconfigRootDir: ".",
        sourceType: "module",
        project: "./tsconfig.json"
    },
    extends: [
        "plugin:import/recommended",
        "plugin:import/typescript"
    ],
    plugins: [
        "@typescript-eslint",
        "import"
    ],
    overrides: [
        {
            files: [
                "src/_migration/**"
            ],
            rules: {
                "import/no-restricted-paths": [
                    "error",
                    {
                        basePath: "./src",
                        zones: [
                            { target: "./_migration", from: "./", except: ['./_migration'] }
                        ],
                    },
                ]
            }
        },
    ],
    rules: {
        "import/no-unresolved": "off",
        "@typescript-eslint/typedef": [
            "error",
            {
                parameter: true
            }
        ]
    }
};

alecthw

when update to Ver. 3.2.2, these errors:

  1:1   error  Resolve error: typescript with invalid interface loaded as resolver  import/no-unresolved
  1:1   error  Resolve error: typescript with invalid interface loaded as resolver  import/order
  1:1   error  Resolve error: typescript with invalid interface loaded as resolver  import/no-self-import
  1:1   error  Resolve error: typescript with invalid interface loaded as resolver  import/extensions

3.2.1 is OK

meriouma

This is a breaking change in v3. Trying to run eslint with eslint-import-resolver-typescript@3+ yields multiple
error Resolve error: File '@equisoft/typescript-config/tsconfig.standards.json' not found.
4:15 error Unable to resolve path to module './some-module

Reproduction branch : https://github.com/kronostechnologies/tax-ca/tree/get-tsconfig-issue
Steps :

  • yarn install
  • yarn eslint

I believe the issue is caused by the change from tsconfig-paths to get-tsconfig (privatenumber/get-tsconfig#26)

kekel87

Hello,

I am updating my Angular project and its dependencies.

eslint-import-resolver-typescript@3.1.4 is not able to resolve aliases to direct file versions anymore.

app.module.ts

import { HeaderModule } from '~app/core/header/header.module'; // This work
import { environment } from '~environment'; // This doesn't work anymore.

tsconfig.json

   "paths": {
      "~environment": ["src/environments/environment"], // Alias to `src/environments/environment.ts` file
      "~shared/*": ["src/app/shared/*" ],
      "~app/*": ["src/app/*" ],
      "~mocks/*": ["src/tests/mocks/*"]
    }

Output:

...angular-seedsrcappapp.module.ts
  11:29  error  Unable to resolve path to module '~environment'  import/no-unresolved

✖ 1 problem (1 error, 0 warnings)

I rolback my version to ^2.7.0 et ça fonctionne.

apss-pohl

apss-pohl

Hi,
since v3 my nuxt3 projects breaks:
error Unable to resolve path to module '#app' import/no-unresolved
Also the IDE complains. If i go back to v2.7.0 everything works as expected.

The tsconfig gets extended with the generated tsconfig which has the path definition for #app
tsconfig.json
"extends": "./.nuxt/tsconfig.json",

/.nuxt/tsconfig.json»

"paths": {
      "#app/*": [
        "../../node_modules/nuxt/dist/app/*"
      ],
}

.eslintrc

 import/resolver:
    typescript:
      project: 
        - ./tsconfig.json
        - apps/*/tsconfig.json
        - apps/render/.nuxt/tsconfig.json

I hope this enough information provided. Let me know if i can help.
Thank you!

JounQin

patrickarlt

Moving this from import-js/eslint-plugin-import#2111 (comment) after import-js/eslint-plugin-import#2111 (comment).

It looks like this was previously discussed in #80 and it was requested that an issue get filed in eslint-plugin-import. import-js/eslint-plugin-import#2111 discusses this but it was recommended that this functionality move to eslint-import-resolver-typescript.

Below is my original comment from the eslint-plugin-import issue slightly modified for clarity.


I’m migrating a large project written in TypeScript to output native ESM modules for Node. This requires all the import statements in TypeScript to end in .js so they get output with the .js extensions and I would like to lint that import statements of file paths end in .js.

I don’t think TypeScript is going to budge on their treatment of extensions, see microsoft/TypeScript#16577 (comment), neither will Node JS back off of required extensions for ESM so it is perfectly valid TypeScript to write this if you are compiling to ESM for Node:

// foo.ts
export const foo = 'foo';

// bar.ts
import { foo } from './foo.js';

Compiles to:

// foo.js
export const foo = 'foo';

// bar.js
import { foo } from './foo.js';

Currently this config produces Missing file extension "ts" for "./foo.js" which is illogical since TypeScript doesn’t actually support .ts on file paths microsoft/TypeScript#37582.

module.exports = {
  root: true,
  parser: "@typescript-eslint/parser",
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: "module"
  },
  plugins: ["@typescript-eslint", "import"],
  extends: ["plugin:import/recommended", "plugin:import/typescript"],
  rules: {
    "import/extensions": ["error", "ignorePackages"]
  },
  settings: {
    "import/extensions": [".js", ".jsx"],
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"]
    },
    "import/resolver": {
      typescript: {
        project: "./"
      }
    }
  }
};

nightah

It appears that some imports that previously did not have any issues with v2.7.1 now are throwing import/no-unresolved errors, specifically as follows:

/srv/repos/authelia/web/src/i18n/index.ts
  1:18  error  Unable to resolve path to module 'i18next'  import/no-unresolved

✖ 1 problem (1 error, 0 warnings)

file: /srv/repos/authelia/web/src/i18n/index.ts
error during build:
Error: 
/srv/repos/authelia/web/src/i18n/index.ts
  1:18  error  Unable to resolve path to module 'i18next'  import/no-unresolved

✖ 1 problem (1 error, 0 warnings)

You can see the IDE also highlighting the same issue:

image

Below is the consistent .eslintrc.js file utilised with both v2.7.1 and v3.1.0:

module.exports = {
    parser: "@typescript-eslint/parser",
    parserOptions: {
        project: "tsconfig.json",
    },
    ignorePatterns: ["build/*", "coverage/*", "!.*.js"],
    settings: {
        "import/resolver": {
            typescript: {},
        },
    },
    extends: ["react-app", "plugin:import/errors", "plugin:import/warnings", "plugin:prettier/recommended", "prettier"],
    rules: {
        "import/order": [
            "error",
            {
                groups: ["builtin", "external", "internal"],
                pathGroups: [
                    {
                        pattern: "react",
                        group: "external",
                        position: "before",
                    },
                ],
                pathGroupsExcludedImportTypes: ["react"],
                "newlines-between": "always",
                alphabetize: {
                    order: "asc",
                    caseInsensitive: true,
                },
            },
        ],
    },
};

After some google-fu it appears I can resolve the issue by including the following extends for the eslint configuration:

"plugin:import/typescript"

I’m not really sure why this seems to resolve the issue, but I’m keen to understand why this has changed between the two versions and if it is perhaps some misconfiguration on my side.

It’s worthwhile mentioning that I did also read the changelog and understandably with the major version bump there are breaking changes I’m just not sure what the expected action is if there’s an adjustment that should be made to work alongside said breaking changes.

JounQin

JounQin

yyynnn

Hi there!

i5 ThinkPad taking off like 747
It takes around 10s to save a file

CMCDragonkai

I came to this repo after this https://github.com/import-js/eslint-plugin-import#typescript says to also install this.

However I tried the rule import/no-cycle, and it worked as long as I added plugin:import/typescript:

  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:prettier/recommended",
    "plugin:import/typescript", // <--- ADDED THIS ONE
    "prettier"
  ],
  "plugins": [
    "import"
  ],

If I didn’t have that plugin, it wouldn’t work.

Now I checked my package-lock.json to see if something was bringing in this package eslint-import-resolver-typescript. But there was nothing.

[nix-shell:~/Projects/TypeScript-Demo-Lib-Native]$ ag 'eslint-import-resolver'
package-lock.json
2943:    "node_modules/eslint-import-resolver-node": {
2945:      "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz",
2953:    "node_modules/eslint-import-resolver-node/node_modules/debug": {
2994:        "eslint-import-resolver-node": "^0.3.6",
10529:    "eslint-import-resolver-node": {
10531:      "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz",
10581:        "eslint-import-resolver-node": "^0.3.6",

Does this mean this package isn’t required for some of the rules in the eslint-import-plugin? Or should I still have this package for other reasons?

joaocasarin

Error: Unable to resolve path to module '@services/CreateUser'.eslint[import/no-unresolved](https://github.com/import-js/eslint-plugin-import/blob/v2.26.0/docs/rules/no-unresolved.md)

Package dependencies:

{
        "eslint": "^8.13.0",
        "eslint-config-airbnb-base": "^15.0.0",
        "eslint-config-prettier": "^8.5.0",
        "eslint-import-resolver-typescript": "^2.7.1",
        "eslint-plugin-import": "^2.26.0",
        "eslint-plugin-prettier": "^4.0.0",
        "typescript": "^4.6.3"
}

tsconfig.json paths:

{
    "baseUrl": ".",
            "paths": {
                "@lambdas/*": ["src/lambdas/*"],
                "@services/*": ["src/services/*"]
            }
}

.eslintrc.js:

module.exports = {
extends: ['airbnb-base', 'prettier'],
    parser: '@typescript-eslint/parser',
    settings: {
        'import/parsers': {
            '@typescript-eslint/parser': ['.ts', '.tsx']
        },
        'import/resolver': {
            node: {
                typescript: {
                    alwaysTryTypes: true,
                    project: './tsconfig.json'
                },
                extensions: ['.js', '.ts']
            }
        }
    },
    parserOptions: {
        ecmaVersion: 12,
        sourceType: 'module'
    },
    plugins: ['@typescript-eslint', 'import', 'prettier']
}

For the typescript build it is apparently good.

AndyClausen

I’ve mapped lodash to lodash-es in paths, but this resolver doesn’t recognize it despite typescript handling it just fine, so if I import like this:

import orderBy from 'lodash/orderBy';
import pick from 'lodash/pick';

it throws this error on both lines:

ESLint: '@types/lodash' should be listed in the project's dependencies. Run 'npm i -S @types/lodash' to add it(import/no-extraneous-dependencies)

.eslintrc.js:

const path = require('path');

module.exports = {
  root: true,
  ignorePatterns: ['node_modules/**/*'],
  extends: ['some-internal-config', 'plugin:import/typescript'], // our internal config imports `typescript-eslint` and some other things
  env: {
    es6: true,
  },
  settings: {
    'import/resolver': {
      typescript: {
        project: [
          path.resolve(__dirname, 'tsconfig.json'),
          path.resolve(__dirname, 'src/tsconfig.app.json'),
        ],
      },
    },
  },
  overrides: [
    {
      files: ['*.ts'],
      parserOptions: {
        project: [
          path.resolve(__dirname, 'tsconfig.json'),
          path.resolve(__dirname, 'tsconfig.lint.json'),
          path.resolve(__dirname, 'src/tsconfig.app.json'),
        ],
        createDefaultProgram: true,
      },
    },
  ],
};

tsconfig.json:

{
  "compilerOptions": {
    "paths": {
      "lodash/*": ["../../node_modules/lodash-es/*"],
      "@types/lodash/*": ["../../node_modules/@types/lodash-es/*"]
    }
  }
}

beetlebum

When using the project in React Native 0.67 and resolver version 2.7, the following error can be observed:
warn Package eslint-import-resolver-typescript has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in /Code/GitHub/app/node_modules/eslint-import-resolver-typescript/package.json

teoxoy

I am currently working on a yarn workspaces monorepo with one eslint config file at the root.
@typescript-eslint/parser supports multiple eslint configs trough parserOptions.projects

I am not sure if this can be automated (i.e. the plugin reads parserOptions.projects)

commit-master

JounQin

kristijorgji

I have a nextjs typescript eslint project where use paths in tsconfig.json like

    "paths": {
      "@/core/*": ["src/core/*"],
      "@/c/*": ["src/c/*"]
    }

Compilation and everything works great, linting fails with
18:23 error Unable to resolve path to module '@/core/useRouter' import/no-unresolved
I am importing in one file under src/pages/Login.tsx import useRouter from '@/core/useRouter';

I am using this plugin with eslint, and versions as below

"eslint": "^7.32.0",
"eslint-import-resolver-typescript": "^2.5.0",
"eslint-plugin-import": "^2.24.2",
"typescript": "^4.4.2"

eslintrc.js

module.exports = {
    root: true,
    parser: '@typescript-eslint/parser',
    plugins: ['import'],
    parserOptions: {
        ecmaFeatures: { jsx: true },
    },
    extends: [
        'eslint:recommended',
        'plugin:@typescript-eslint/eslint-recommended',
        'plugin:@typescript-eslint/recommended',
        'plugin:react/recommended',
        'plugin:jsx-a11y/recommended',
        'plugin:import/errors',
        'plugin:import/warnings',
        'plugin:import/typescript',

        // Prettier plugin and recommended rules
        'plugin:prettier/recommended',
    ],
    rules: {
        // Include .prettierrc.js rules
        'prettier/prettier': ['error', {}, { usePrettierrc: true }],

        'no-empty': 'off',
        'react/prop-types': 'off',
        '@typescript-eslint/ban-ts-comment': 'off',
        '@typescript-eslint/no-non-null-assertion': 'off',
        'jsx-a11y/click-events-have-key-events': 'off',
        'jsx-a11y/no-static-element-interactions': 'off',
        'jsx-a11y/interactive-supports-focus': 'off',
        'jsx-a11y/no-noninteractive-element-interactions': 'off',
        'jsx-a11y/no-onchange': 'off',
    },
    settings: {
        'import/extensions': ['.js', '.jsx', '.tsx', '.ts'],
        'import/resolver': {
            typescript: {},
        },
    },
};

bukharov

We have a monorepo with several applications and some files have identical names. The resolver picks an incorrect file and it gets marked as external which interferes with other import rules.

For instance there’s applications/employer/Application.tsx that imports Application.actions.ts which is in the same folder.
When eslint-plugin-import invokes this resolver it provides the following arguments:
modulePath = Application.actions
sourceFile = /applications/employer/Application.tsx

Then the import gets resolved to : /applications/admin/Application.actions.
Which is from a different application.

Here’s my settings object:

    'import/resolver': {
      typescript: {
        alwaysTryTypes: true,
        project: ['applications/*/tsconfig.json'],
      },
    },

And some logs:

eslint-import-resolver-typescript looking for: Application.actions +1ms
eslint-import-resolver-typescript found multiple matching ts paths: [
  '/applications/admin/Application.actions',
  '/applications/employer/Application.actions'
] +0ms
eslint-import-resolver-typescript matched ts path: /applications/admin/Application.actions +1ms
eslint-import-resolver-typescript matched node path: /applications/admin/Application.actions.ts +0ms

Is this a bug or I’m doing something wrong? I believe it should pick the «closest» tsconfig.json to the source file rather than picking the first in the list.

TypeScript uses an invalid interface to load itself. This type of error is often associated with the use of a language that is not compatible with it. It can occur in a program using the NodeJS programming language or in any other programming language. It can also occur in a script written in another language. In this article, we will discuss the problem and offer some possible solutions. The first step in the resolution of this error is to find the exact cause of this problem.

This error occurs when a library contains an outdated typescript version. If the error is caused by an older version of the language, you may want to upgrade your browser. This will help you fix the problem in the future. In the meantime, here are some methods you can use to avoid this problem: (1) VSCode’s format on save feature. (2) Prettier, eslint, and Husky.

If you’re using a browser that doesn’t support TypeScript, you might want to upgrade. In particular, try using Firefox’s watch mode. This mode caches the files it needs, and prevents it from being downloaded to your computer. This method is not supported by older versions of this browser. Instead, update your browser to the latest stable version to fix the issue. You can also try a different type of browser, such as Chrome or Firefox.

As an alternative to eslint, you can also use prettier or VSCode’s format on save feature. Alternatively, you can use a scripting tool like Husky to run your Git commands. This method may be time consuming and may not be appropriate for your project. Aside from this, some projects don’t require typescript code checking. This method is not suitable for all types of code.

Using watch mode allows you to avoid this error and keep a clean code structure. In addition, this option makes it easier to maintain code in an OO environment, because every file access will be cached. And every time you need to perform a file operation, you can set a cache before you execute. And when you’re done, you’ll get a stack trace of the entire project.

To resolve this error, you can either use a different type of interface or use a watch mode. This mode will allow you to configure the interface of your application and prevent it from crashing. If you have two different interfaces, you can simply rename the files. But if you’d rather have a single, then watch mode is the best option. With this method, you can create a new class based on your existing one.

To resolve this error, use watch mode. The watch mode will let you use watch mode. This mode will enable you to create a nested tree of promises. As a result, a single promise will be loaded with every other one. A chain of promises is an arbitrary set of objects. A single resolution will always cause the other to crash. This method will be asynchronous, but it will allow you to work with it without a break.

You can use watch mode to prevent this error. It will automatically purge the cache of files that are modified. When you use watch mode, you should not worry about the old version of the browser as it will not be affected. This is because the watch mode will prevent the code from being corrupted. It will prevent errors from occurring if it isn’t working in the same way as the previous one.

To resolve this error, use VSCode. Its format on save feature will make your code more readable. You can also use eslint, prettier, and Husky to run your Git commands. But this process will take some time, and some projects might not need it. Then, you can try other solutions that are more efficient. When you need more time to check your code, you can check the code with VSCode.

Понравилась статья? Поделить с друзьями:
  • Residual std error
  • Residual standard error что это
  • Residual square error
  • Resideo dkg 972 n коды ошибок
  • Resident evil village ошибка нехватки места 21 мб