首页 > 解决方案 > Eslint plugin import throws "import/no-unresolved" on specific modules inside a Lerna package

问题描述

I'm using Lerna for the first time, and I want to create a monorepo of microservices, so inside a service I have axios, puppeter & joi installed, so eslint-plugin-import takes them as unresolved because they are not in the root package.json

I don't know how to change my current Eslint config, and I'm pretty sure that I don't need to create an Eslint config for every service inside packages folder, because I have seen repos with lerna that do not do that

I'm using Airbnb's rules

"eslint": "5.3.0",
"eslint-config-airbnb": "17.1.0",
"eslint-plugin-import": "2.16.0",
"eslint-plugin-jsx-a11y": "6.2.0",
"eslint-plugin-react": "7.12.4",

And, this is my .eslintrc

{
  "extends": "airbnb",
  "rules": {
    "no-unused-vars": [
      "error",
      {
        "argsIgnorePattern": "next"
      }
    ]
  },
  "env": {
    "browser": true,
    "es6": true,
    "mocha": true,
    "node": true
  }
}

~/api-gateway/packages/service-accountancy/lib/scrapper.js 2:27 error Unable to resolve path to module 'puppeteer' import/no-unresolved 3:22 error Unable to resolve path to module 'puppeteer/lib/Page' import/no-unresolved

~/api-gateway/packages/service-accountancy/src/api/api.js 2:21 error Unable to resolve path to module 'joi' import/no-unresolved

~/api-gateway/packages/service-accountancy/src/repository/repository.js 2:23 error Unable to resolve path to module 'axios' import/no-unresolved

~/api-gateway/packages/service-accountancy/src/schemas/portalRequest.js 1:21 error Unable to resolve path to module 'joi' import/no-unresolved

标签: node.jseslintlerna

解决方案


The eslint-plugin-import package was actually doing its job, those packages were no downloaded at the time Eslint was running


推荐阅读