0

I'm trying to use absolute path import form my custom modules and VSCode has no prob recognising them. The problem is that when I run firebase deploy which runs first eslint I get errors.

3:24 error Unable to resolve path to module '@src/stripe/lib/secret-key' import/no-unresolved

I have tried to set this

"import/resolver": {
   "typescript": {}
}

in the eslintrc.js but I just get more and more errors. I have also tried to install some plugins but no luck.

Here is the line which throws the error.

import { stripe } from '@src/stripe/lib/secret-key'

tsconfig

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "allowSyntheticDefaultImports": true,
    "baseUrl": "./",
    "paths": {
      "@src/*": [
        "./src/*"
      ]
    }
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

eslintrc.js

module.exports = {
  env: {
    browser: true,
    es6: true,
    node: true,
  },
  extends: [
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript",
  ],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: "tsconfig.json",
    sourceType: "module",
  },
  plugins: [
    "@typescript-eslint",
    "import",
  ],
  rules: {
    "@typescript-eslint/adjacent-overload-signatures": "error",
    "@typescript-eslint/no-empty-function": "error",
    "@typescript-eslint/no-empty-interface": "warn",
    "@typescript-eslint/no-floating-promises": "error",
    "@typescript-eslint/no-namespace": "error",
    "@typescript-eslint/no-unnecessary-type-assertion": "error",
    "@typescript-eslint/prefer-for-of": "warn",
    "@typescript-eslint/triple-slash-reference": "error",
    "@typescript-eslint/unified-signatures": "warn",
    "constructor-super": "error",
    eqeqeq: ["warn", "always"],
    "import/no-deprecated": "warn",
    "import/no-extraneous-dependencies": "error",
    "import/no-unassigned-import": "warn",
    "no-cond-assign": "error",
    "no-duplicate-case": "error",
    "no-duplicate-imports": "error",
    "no-empty": [
      "error",
      {
        allowEmptyCatch: true,
      },
    ],
    "no-invalid-this": "error",
    "no-new-wrappers": "error",
    "no-param-reassign": "error",
    "no-redeclare": "error",
    "no-sequences": "error",
    "no-shadow": [
      "error",
      {
        hoist: "all",
      },
    ],
    "no-throw-literal": "error",
    "no-unsafe-finally": "error",
    "no-unused-labels": "error",
    "no-var": "warn",
    "no-void": "error",
    "prefer-const": "warn",
  },
  settings: {
    jsdoc: {
      tagNamePreference: {
        returns: "return",
      },
    },
  },
};

Any idea how to make this work?

M1X
  • 4,971
  • 10
  • 61
  • 123
  • Are you sure your folder name starts with a `@`? that's very unusual. – Christian Fritz May 19 '21 at 15:02
  • 1
    It doesn’t but its defined to be imported that way in the paths inside tsconfig – M1X May 19 '21 at 15:12
  • Another post refering to the error you're receiving states that following [this](https://stackoverflow.com/a/56696478/15451750) answer fixes the issue you're experiencing. However, I share the concern with the `@` in the paths, if the suggested approach doesn't work maybe try removing them to see what happens. – Roger May 20 '21 at 15:40

0 Answers0