Javascript: import/no-unresolved thrown when using app-module-path package

Created on 1 May 2016  路  4Comments  路  Source: airbnb/javascript

We're currently using app-module-path to make our import paths saner. Since the update to 2.0, I've been getting import/no-unresolved errors in my linter output when the modified paths are used.

I can't find this rule in the eslint docs, is this something that is specific to airbnb? I've set this to warn status so it doesn't impact me as much, but would like to know if a fix can be implemented.

Most helpful comment

This was my solution (add to your .eslintrc "settings" entry if it already exists):

  "settings": {
    "import/resolver": {
      "node": {
        "moduleDirectory": [
          "node_modules",
          "src" // replace with your app-module-path directory
        ]
      }
    }
  }

There are more options besides "moduleDirectory", see here.

All 4 comments

This comes from the eslint import plugin. In your case, you should probably disable the rule since you're using a custom way to specify your import paths.

Also, it seems like your module is not really required.
You could achieve the same thing by using the environment variable NODE_PATH before running your script.

With this NODE_PATH=./src, you can require everything inside src, and because it's a native node thing, I guess the default Node resolver will be able to resolve the files.

This rule comes from eslint-plugin-import, which you can tell from the rule name because the part before the / refers to an eslint plugin of the same name.

You can probably configure the node resolver to do what you want. If that doesn't work, you could probably add a resolver for this.

This was my solution (add to your .eslintrc "settings" entry if it already exists):

  "settings": {
    "import/resolver": {
      "node": {
        "moduleDirectory": [
          "node_modules",
          "src" // replace with your app-module-path directory
        ]
      }
    }
  }

There are more options besides "moduleDirectory", see here.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

progre picture progre  路  3Comments

stephenkingsley picture stephenkingsley  路  3Comments

zurfyx picture zurfyx  路  3Comments

danielfttorres picture danielfttorres  路  3Comments

olalonde picture olalonde  路  3Comments