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

import/named requires 'typescript-eslint-parser' #1285

Closed
lednhatkhanh opened this issue Feb 12, 2019 · 13 comments
Closed

import/named requires 'typescript-eslint-parser' #1285

lednhatkhanh opened this issue Feb 12, 2019 · 13 comments

Comments

@lednhatkhanh
Copy link

This is my .eslintrc config:

{
  "parser": "@typescript-eslint/parser",
  "settings": {
    "import/resolver": {
      "babel-module": {}
    }
  },
  "extends": [
    "airbnb",
    "plugin:@typescript-eslint/recommended",
    "plugin:import/typescript",
    "plugin:prettier/recommended",
    "prettier/@typescript-eslint"
  ],
  "plugins": ["react-hooks", "emotion"],
  "rules": {
    "react-hooks/rules-of-hooks": "error",
    "emotion/jsx-import": 0,
    "react/react-in-jsx-scope": 0,
    "react/jsx-filename-extension": [1, { "extensions": [".tsx"] }],
    "import/prefer-default-export": 0
  }
}

I'm importing like this:

import { Button } from "../src/components/button";

The error:

Parse errors in imported module '../src/components/button': Cannot find module 'typescript-eslint-parser' (undefined:undefined)eslint(import/named)
@ljharb

This comment has been minimized.

@lednhatkhanh

This comment has been minimized.

@ljharb
Copy link
Member

ljharb commented Feb 12, 2019

hmm, the implication is that one of your plugins or shared configs is still pointing to the old typescript parser.

@lednhatkhanh
Copy link
Author

lednhatkhanh commented Feb 12, 2019

So I updated my config to this:

{
  "parser": "@typescript-eslint/parser",
  "extends": [
    "plugin:@typescript-eslint/recommended",
    "plugin:import/errors",
    "plugin:import/typescript"
  ],
  "plugins": ["import"]
}

And the problem is still there.

@lednhatkhanh
Copy link
Author

So I saw this pr #1283 and it fixes the problem, but requires me to install typescript-eslint-parser and eslint-import-resolver-typescript.

@billyjanitsch
Copy link

This was already fixed in bdc05aa. (Note the change to config/typescript.js.) eslint-plugin-import just needs a new release.

@ljharb ljharb closed this as completed Feb 14, 2019
@kachkaev
Copy link

@benmosher it'd be awesome if you could cut a new release! 🙏 Can't wait to use eslint-plugin-import with @typescript-eslint! 🤩

@MatiasOlivera
Copy link

Until there is a new release, a workaround that works for me is:

// .eslintrc.js

var jsExtensions = ['.js', '.jsx'];
var tsExtensions = ['.ts', '.tsx'];
var allExtensions = jsExtensions.concat(tsExtensions);

module.exports = {
  plugins: ['import'],
  settings: {
    'import/extensions': allExtensions,
    'import/parsers': {
      '@typescript-eslint/parser': tsExtensions
    },
    'import/resolver': {
      'node': {
        'extensions': allExtensions
      }
    }
  }

}

It's necessary not to extend the configuration from "plugin:import/typescript".

@lednhatkhanh There is no need to install typescript-eslint-parser and eslint-import-resolver-typescript

MatiasOlivera added a commit to MatiasOlivera/ypf-tienda that referenced this issue Feb 22, 2019
Error: Parse errors in imported module. Cannot find module 'typescript-eslint-parser'
Issue: import-js/eslint-plugin-import#1285
@gabeidx
Copy link

gabeidx commented Mar 19, 2019

For anyone finding this ticket, this has not been released yet. @MatiasOlivera solution still works.

@ljharb Is there a big picture here that we are missing? If so, would it make sense to keep this ticket open until a new release is cut? At the moment the closed status feels a bit misleading. Thanks!

cc @benmosher

@ljharb
Copy link
Member

ljharb commented Mar 20, 2019

@GabrielIzaias no, issues (not tickets) are pretty universally closed when fixes are merged, not when they’re released (an unrelated action)

@kachkaev
Copy link

Can't wait for a release with this fix to migrate more projects from tslint to eslint 🙌 🙏 @MatiasOlivera, thanks for the workaround!

@nikolalukovic
Copy link

Any update on when is this going to get released?

@Lisa-V-Sau
Copy link

Lisa-V-Sau commented Mar 8, 2021

Until there is a new release, a workaround that works for me is:

// .eslintrc.js

var jsExtensions = ['.js', '.jsx'];
var tsExtensions = ['.ts', '.tsx'];
var allExtensions = jsExtensions.concat(tsExtensions);

module.exports = {
  plugins: ['import'],
  settings: {
    'import/extensions': allExtensions,
    'import/parsers': {
      '@typescript-eslint/parser': tsExtensions
    },
    'import/resolver': {
      'node': {
        'extensions': allExtensions
      }
    }
  }

}

It's necessary not to extend the configuration from "plugin:import/typescript".

@lednhatkhanh There is no need to install typescript-eslint-parser and eslint-import-resolver-typescript

This worked for me, however rather than use import I had to change it to module as import is reserved.

thlmenezes added a commit to TMTecnologia/turborepo-typescript-fullstack that referenced this issue Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

8 participants