[go: nahoru, domu]

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

[import/no-unresolved] not working for index.js #1292

Open
a-x- opened this issue Feb 19, 2019 · 16 comments
Open

[import/no-unresolved] not working for index.js #1292

a-x- opened this issue Feb 19, 2019 · 16 comments

Comments

@a-x-
Copy link
a-x- commented Feb 19, 2019

similar but different: #1124

screenshot 2019-02-19 at 20 45 03

file struct:

utils/
    index.js
components/
    Foo.jsx
.eslintrc.js
webpack.config.js

utils/index.js:

export function getPromise () { return 42; }

components/Foo.jsx:

import { getPromise } from 'utils';

.eslintrc:

{
  "parser": "babel-eslint",
  "plugins": [
    "import",
  ],
  "settings": {
    "import/resolver": {
      "webpack": {
        "config": path.resolve(__dirname, "webpack.config.js"),
      }
    },
  },
  "rules": {
    "import/no-unresolved": ["error", {commonjs: true, caseSensitive: true}],
    // ...
  }
}

webpack.config.js:

{
  context: root,
  resolve: {
    modules: [root, 'node_modules'],
    extensions: ['.js', '.jsx', '.json', '.coffee', '.cjsx'],
  },
  // ...
}

versions: all are latest

@ljharb
Copy link
Member
ljharb commented Feb 20, 2019

How does utils work when it's not inside node_modules?

@a-x-
Copy link
Author
a-x- commented Feb 22, 2019

due to webpack aliasing and module paths:
modules: [root, 'node_modules']
root here contains utils dir along with all the shown fs structure.

@a-x-
Copy link
Author
a-x- commented Feb 22, 2019

No one wanna write awful '../../../../MyComponent' imports, right? :)

@ljharb
Copy link
Member
ljharb commented Feb 22, 2019

I do - I think they're a correct and proper indication that I have code that needs extracting into a separate package :-)

In this case, tho, the error message is warning you about capitalization. If you import from utils/index.js, what happens?

@a-x-
Copy link
Author
a-x- commented Feb 23, 2019

utils/index.js and utils/index work
capitalization is correct as I can check (ls src)

@a-x-
Copy link
Author
a-x- commented Feb 23, 2019

extracting into a separate package

Yes, but package can be local (that is well-known practice called Vendoring as I know),
so I setups webpack to looking for modules not in the node_modules only

dependency path variable is common computer engineering practice too

@ljharb
Copy link
Member
ljharb commented Feb 23, 2019

You can and should vendor into node_modules itself and use bundledDependencies to tell npm to ignore that folder; it’s not a good practice imo to create alternate or different directories for third party code.

However, the utils issue is interesting. I’d still expect it to work and the implication is that there’s either a bug we need to fix, or that there’s something weird with capitalization of your files or case sensitivity of your machine.

@a-x-
Copy link
Author
a-x- commented Feb 28, 2019

That's interesting solution... We'll think about it.

I have default macOS config. MacOS suggests case-insensitive FS setting by default.
Anyway, I can check case in my github repo. so utils/index.js is not capitalized 🤔

@a-x-
Copy link
Author
a-x- commented Mar 4, 2019

That's interesting solution... We'll think about it.

really we're think that both tricks with moving all our directories into node_modules,
and using paths with ../../../ are highly weird.

all our friends use absolute paths as single useful way to fight the path complexity (simplify refactorings, decrease code blowing and etc.)

I can help fix that maybe, if you can help with details

@a-x-
Copy link
Author
a-x- commented Mar 4, 2019

Currently I disabled caseSensitive option, but it's not ideal solution for us.

True-negative checks with caseSensitive: true are useful for my team

@ljharb
Copy link
Member
ljharb commented Mar 5, 2019

Using absolute paths tends to couple things to specific developer’s machines (since all your files should only be inside $HOME); it’s not a good practice.

There’s definitely a bug here, and yes it’d be great to get a PR for it.

@a-x-
Copy link
Author
a-x- commented Mar 6, 2019

Excuse my inaccuracy

I'm not about /Users/mxtnr/projects/project/blah/blah/Foo.jsx
I'm about blah/blah/Foo.jsx
rather than ../../../blah/Foo.jsx

@Germain67
Copy link

Any news on this? We encountered the same issue in our project.

@OoDeLally
Copy link

How do people solve this issue as of today?

@a-x-
Copy link
Author
a-x- commented Aug 9, 2019

@OoDeLally, I fixed it for most cases with that workaround:
#1292 (comment)

but my project has not case mismatches.

so I wanna to get caseSensitive: true config back because some juniors can cause some naming/import case mismatching problems in the future.

@xianshenglu
Copy link

usually I'd like to write code like import utils from '@/utils' rather than import utils from '@/utils/index.js'.

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

No branches or pull requests

6 participants