Reputation: 874
I'm was trying to connect to my Firebase app by following the docs, but ESLint is complaining. I have already checked a related question, but the solutions proposed there doesn't seem to work for me. I have the following .eslint.js file:
module.exports = {
extends: [
'airbnb-typescript/base',
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:typescript-sort-keys/recommended',
'plugin:import/recommended',
'prettier'
],
parser : '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: {
modules: true
},
ecmaVersion: 6,
project : './tsconfig.json',
sourceType : 'module'
},
plugins: ['@typescript-eslint', 'typescript-sort-keys', 'sort-keys-fix'],
rules : { ... }
}
Upvotes: 27
Views: 5356
Reputation: 141
As mentioned in this github issue:#1359 It looks like import/no-unresolved is part of a custom ESLint plugin. I believe this is a bug/limitation in eslint-plugin-import (see issue #1868 ). The code is indeed valid, and compiled by tsc. VSCode can also successfully resolve the module entry points.
So I now just suppress the warning for firebase-admin using the following eslint rule:
'import/no-unresolved': [
'error',
{
ignore: ['^firebase-admin/.+'],
},
],
This worked for me as the solution is not yet merged in Eslint.
Upvotes: 6
Reputation: 3069
Per this issue, "By default eslint-plugin-import does not support exports property in package.json.
Link to related issue: import-js/eslint-plugin-import#1810
Solution is to add plugin: https://github.com/import-js/eslint-import-resolver-typescript which introduces the support."
e.g.
add
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"],
},
"import/resolver": {
"typescript": {
"alwaysTryTypes": true,
"project": "./tsconfig.json",
},
},
to your eslintrc.js, and npm i -D eslint-plugin-import eslint-import-resolver-typescript
Upvotes: 5
Reputation: 2220
Here is how I managed to fix this error, the problem is that typescript don't find it but the package is actually there, so just added path to it.
{
"compilerOptions": {
...
"paths": {
"firebase-admin/*": [
"node_modules/firebase-admin/lib/*"
]
}
}
My eslint config, since I made a while ago, I wan't to tell that only the setting part is important for the correct linking, but I have put all options relative to typescript in case.
module.exports = {
...,
// not sure it is relevant for all projects
parserOptions: {
sourceType: 'module',
project: ['./tsconfig.json'],
tsconfigRootDir: __dirname,
},
parser: '@typescript-eslint/parser',
// Important part
settings: {
'import/resolver': {
typescript: {
alwaysTryTypes: true,
project: [
'./tsconfig.json', // path to tsconfig
],
},
},
},
};
Upvotes: 0
Reputation: 47853
As of Firebase Admin v10 it uses exports
in package.json
for defining entry points. eslint-plugin-import
does not support exports
. Until it does you'll have to disable import/no-unresolved
entirely or for each violation.
// eslint-disable-next-line import/no-unresolved
Upvotes: 31