question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resolve the configuration file path in the commonjs style

See original GitHub issue

The version of ESLint you are using.

4.19.1

The problem you want to solve.

Assume that I have an eslint configuration file whose path is <ProjectRoot>/path/to/eslint-configuration/index.js, and I want to use it as the following way:

In package.json:

"eslintConfig": {
    "extends": "./path/to/eslint-configuration"
  }

Eslint can’t read the configuration file path and throws an error (I have simplified the paths in the error message):

Cannot read config file: /absolute/xx/<ProjectRoot>/path/to/eslint-configuration Error: EISDIR: illegal operation on a directory, read Referenced from: /absolute/xx/<ProjectRoot>/package.json

When I first want to target the eslint configuration to a file is relative to my project, my initial intuition was writing it in the commonjs way. I hope that eslint would resolve ./path/to/eslint-configuration to /absolute/xx/<ProjectRoot>/path/to/eslint-configuration/index.js. But it will not actually.

It’s counterintuitive that the path needed by node application could not be resolved in the “node” way. I know I can write down the full path of which file I want to target, but there is a better way to solve it.

Your take on the correct solution to problem.

As the current strategy of how eslint resolves the configuration file is the following: https://github.com/eslint/eslint/blob/master/lib/config/config-file.js#L453-L484

So I read the source codes about how eslint resolves configuration file path. I found that the strategy is complicated due to prefixes like eslint-config- and eslint-plugin-. But what I want is still feasible, because abbreviated config / plugin package name is different with absolute path. Resolve the absolute path by require.resolve() is feasible and has no impact on other places.

All I need to do is wrapping the fullPath with require.resolve():

https://github.com/eslint/eslint/blob/master/lib/config/config-file.js#L457

@not-an-aardvark

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
not-an-aardvarkcommented, May 7, 2018

Thanks for creating an issue, I think I understand the motivation now.

I have a few concerns about making this change:

  • Unlike Node, ESLint also loads YAML files for configs. It seems like it could be confusing if ./path/to/eslint-configuration works when the config is located at ./path/to/eslint-configuration/index.js, but fails when the config is located at ./path/to/eslint-configuration/index.yml.
  • This would limit our flexibility to change how configs are resolved in the future, e.g. if we want to treat relative paths differently somehow in a way that would be incompatible with how Node loads files.

Overall, since the benefit of this change seems fairly minor (it just saves a few keystrokes for the one-time use case of creating a config file), I’m leaning against wanting to add it. However, I’m not strongly opposed, if there are other team members who think this would be a worthwhile change.

0reactions
platinumazurecommented, May 25, 2018

Closing as there doesn’t seem to be interest in pursuing this at this time. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

CommonJS modules | Node.js v19.3.0 Documentation
In Node.js, each file is treated as a separate module. ... The relative paths of POSIX style are resolved in an OS independent...
Read more >
TSConfig Reference - Docs on every TSConfig option
js style resolution. The configuration from the base file are loaded first, then overridden by those in the inheriting config file. All relative...
Read more >
Resolve | webpack
Configure how modules are resolved. For example, when calling import 'lodash' in ES2015, the resolve options can change where webpack goes to look...
Read more >
Resolving require paths with webpack - Stack Overflow
I use alias{ mydir: path. resolve( __dirname, 'path', 'to', 'mydir' ) and require( 'mydir/myfile. js' ) works just fine.
Read more >
Configuration File - Karma
To overcome this issue you need to configure ts-node to use commonjs module format. ... All of the configuration options, which specify file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found