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/default error in monorepo project in Typescript #45

Closed
ludovicmnji opened this issue May 6, 2020 · 3 comments
Closed

import/default error in monorepo project in Typescript #45

ludovicmnji opened this issue May 6, 2020 · 3 comments

Comments

@ludovicmnji
Copy link

ludovicmnji commented May 6, 2020

I'm trying to use eslint-import-resolver-typescript in a monorepo project but I have an unresolved ESlint error despite the right config (I believe).

This is the architecture of the project:

api/
  src/
    index.ts
  package.json
  tsconfig.json
app/
  package.json
  tsconfig.json
.eslintrc
tsconfig.json
package.json

And this is the configuration of each config files:

tsconfig.json

{
  "compilerOptions": {
    "allowJs": false,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "lib": ["dom", "es2020"],
    "module": "es2020",
    "moduleResolution": "node",
    "noFallthroughCasesInSwitch": true,
    "noImplicitAny": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": true,
    "target": "es2020",
    "typeRoots": ["typings", "node_modules/@types"]
  },
  "references": [
    {
      "path": "./api"
    },
    {
      "path": "./app"
    }
  ]
}

api/tsconfig.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "baseUrl": "./src",
    "composite": true,
    "module": "commonjs",
    "outDir": "dist",
  },
  "include": ["./src/**/*.ts"],
  "exclude": ["node_modules", "dist"]
}

app/tsconfig.json

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "baseUrl": "./",
    "composite": false
  },
  "exclude": ["node_modules"],
  "include": ["./**/*.ts", "./**/*.tsx"]
}

.eslintrc

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2020,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    },
    "project": ["./api/tsconfig.json", "./app/tsconfig.json"]
  },
  "plugins": ["@typescript-eslint", "import"],
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript",
    "plugin:prettier/recommended"
  ],
  "env": {
    "browser": true,
    "node": true
  },
  "settings": {
    "react": {
      "version": "detect"
    },
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"]
    },
    "import/resolver": {
      "typescript": {
        "directory": ["./api/tsconfig.json", "./app/tsconfig.json"]
      }
    }
  }
}

In my api/src/index.ts file when I import express with default import syntax import express from "express" I have this error :

No default export found in imported module "express". eslint(import/default)

I have @types/express installed in devDependencies. Could you check if I missed something in my ESlint config or if it's a bug with composite tsconfig that doesn't understand allowSyntheticDefaultImports option ?

@JounQin
Copy link
Collaborator

JounQin commented May 6, 2020

@JounQin JounQin closed this as completed May 6, 2020
@ludovicmnji
Copy link
Author

Thanks for your answer @JounQin . I'm not sure to understand, the only way to fix this is to disable the rule 😨?

@JounQin
Copy link
Collaborator

JounQin commented May 6, 2020

@ludovicmnji Yes for now, and wait the merged PR of eslint-plugin-import release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants