Lerna: ESLint and import/no-unresolved rule

Created on 29 May 2019  路  3Comments  路  Source: lerna/lerna

Hello.
I'm struggling to setup my eslintrc and the import/no-unresolved rule that fires everywhere. My only solution for now is to disable it.

Expected Behavior

Running eslint --ext .js,.jsx . should not trigger false import/no-unresolved errors.

Current Behavior

The command triggers import/no-unresolved error on every module import.

import React from 'react'; // Unable to resolve path to module 'react'       import/no-unresolved
import foo from './bar'; // No error

Shared .eslintrc.js


module.exports = {
  'extends': [
    'airbnb',
  ],
  'env': {
    'node': true,
  },
  'settings': {
    'import/parser': 'babel-eslint',
    'import/ignore': [
      'node_modules',
      '.json$',
    ],
    'import/resolver': {
      'babel-module': {}
    },
  },
  'plugins': [
    'react-hooks'
  ],
  'rules': {
    'no-console': 'error',
    'generator-star-spacing': 'off',
    'import/default': 'warn',
    'import/prefer-default-export': 'off',
    'new-cap': 'off',
    'require-jsdoc': [
      'error',
      {
        'require': {
          'FunctionDeclaration': true,
          'MethodDefinition': true,
          'ClassDeclaration': false
        }
      }
    ],
    'spaced-comment': [
      'error',
      'always',
      {
        'block': {
          'exceptions': ['*']
        }
      }
    ],
    'valid-jsdoc': [
      'error',
      {
        'requireParamDescription': false,
        'requireReturnDescription': false,
        'requireReturn': false
      }
    ],
    'comma-dangle': [
      'error', {
        'arrays': 'always-multiline',
        'exports': 'always-multiline',
        'functions': 'ignore',
        'imports': 'always-multiline',
        'objects': 'always-multiline'
      }
    ],
    'max-len': 'off',
    'react-hooks/rules-of-hooks': 'error',
    'react-hooks/exhaustive-deps': 'warn'
  },
  'parser': 'babel-eslint',
};

Monorepo .eslintrc


{
  "extends": "./node_modules/@internal-shared-package/.eslintrc.js",
  "rules": {
    "import/no-unresolved": "off",
  },
  "env": {
    "jest": true
  }
}

Any idea what's wrong with this configuration?

Most helpful comment

import/no-unresolved is definitely relevant to any package repository, _especially_ one managed by Lerna. import/no-extraneous-dependencies should certainly be turned off in test files if the deps are hoisted to the root.

All 3 comments

Hm, according to plugin's documentation, it "Ensures an imported module can be resolved to a module on the local filesystem". But Lerna's bootstrapped and cross-symlinked dependencies will be local...

Personally, I'm not using this rule; out of import/* rules, I'm using only import/no-extraneous-dependencies with exclusion for dev dependencies.

"import/no-extraneous-dependencies": [
      "error",
      {
        "devDependencies": [
          "**/*test.js",
          "test/**/*.*",
          "test-util/**/*.*",
          "rollup.config.js"
        ]
      }
    ],

I might be wrong but import/no-unresolved seems this rule is not applicable in Lerna monorepos.

Thank you @revelt for your response, that makes sense.
For import/no-extraneous-dependencies I did pretty much the same thing yes.

  "overrides": [
    {
      "files": "**/*{babel,test,stories}.{js,jsx}",
      "rules": {
        "import/no-extraneous-dependencies": "off"
      }
    }
  ],

import/no-unresolved is definitely relevant to any package repository, _especially_ one managed by Lerna. import/no-extraneous-dependencies should certainly be turned off in test files if the deps are hoisted to the root.

Was this page helpful?
0 / 5 - 0 ratings