Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure node resolver #1131

Closed
binarymist opened this issue Jul 4, 2018 · 9 comments
Closed

Configure node resolver #1131

binarymist opened this issue Jul 4, 2018 · 9 comments
Labels

Comments

@binarymist
Copy link

binarymist commented Jul 4, 2018

I'm not exactly sure how this is supposed to work, but it appears as though I'm doing things the right way.

In my .eslinrc.js I have:

module.exports = {
  ...
  env: {
    'node': true
  },
  settings: {
    'import/resolver': {
      'node': {
        'paths': ['./config'],
        'moduleDirectories': ['node_modules']
      }
    }    
  }
};

but eslint is still complaining:

error Unable to resolve path to module 'config/config' import/no-unresolved

on a file that has const config = require('config/config'); at the top.

I'm using app-module-path for my package deps.

Opened issue from #506

Same deal for ./src in the rood dir. package.json is in the root dir. Have tried adding all the incantations to the paths and moduleDirectories arrays.

@binarymist
Copy link
Author

Adding the 'import/no-unresolved': [{commonjs: true}] to the .eslingrc.js removes the error, I'm not exactly sure what's going on here though. I'm not sure what the 2 is for in the import/no-unresolved: [2, {commonjs: true, amd: true}], it doesn't appear to be documented.

@ljharb
Copy link
Member

ljharb commented Jul 4, 2018

It means “error”, and it’s how all eslint rules are configured (with a severity of 0/1/2 or off/warn/error)

By adding it without the 2, you’re disabling the rule, which is unlikely to be what you want.

Can you share your entire eslintrc, with nothing elided?

@binarymist
Copy link
Author

binarymist commented Jul 4, 2018

Ah, OK, thanks.
.eslingrc.js source

@ljharb
Copy link
Member

ljharb commented Jul 5, 2018

The docs say that “paths” must be an absolute path - not a relative one. https://github.com/benmosher/eslint-plugin-import/tree/master/resolvers/node

@binarymist
Copy link
Author

Ah, tried that.

@ljharb
Copy link
Member

ljharb commented Jul 5, 2018

In that case, I'm not really sure (but i don't know what app-module-path is).

@binarymist
Copy link
Author

Ah, sorry... app-module-path

@benmosher
Copy link
Member

benmosher commented Sep 9, 2018

I'm using app-module-path for my package deps.

Looking briefly at the docs for app-module-path, your best bet is to use absolute paths (generally by using some sort of path.join(__dirname, './config') incarnation).

FWIW I think you want paths: [__dirname] if I understand your folder layout. Module resolution will be attempted starting at the path as a root, so to resolve config/config you'd be resolving ./config/config/config.js given your pasted config.

Closing because it is tough to manage config questions but other ideas/responses from the community are still welcome.

@Venryx
Copy link

Venryx commented Sep 12, 2019

@benmosher path.resolve("Source") worked for me. (for others who stumble across this thread)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants