Linting issue with imports


#1

I am unable to resolve the linting issue “import/no-unresolved” if using import statements like this

import { xxx } from '/client/xxx/yyy’
or
import { xxx } from ‘/server/xxx/yyy’

Thanks in advance for help.


#2

This linting error just tells you that the file you’re trying to import cannot be found.
See here.

Are you sure you’re pointing at the right location?

Obviosuly this can also happen if you’re writing your test first (i.e. TDD) and implement the actual code afterwards. In this case, that lint warning would be expected.


#3

Actually the files are there and there is no linting errors when using the relative path for e.g.

import xxx from '../client/xxx';

The linting errors are only occurring when using the following import statements.

import xxx from '/client/xxx'; { this works only linting issue }


#4

Ah ok.
Well I’m no expert, but Meteor’s final paths (after build) may be different than what your linter is looking at - especially if you’re using absolute paths as in your second example.

So I’d definitely recommend using relative paths only.


#5

And simply silencing the linter is out of the question? Otherwise you could “fix” it with the solution @will is providing here:

https://forums.meteor.com/t/code-style-article/20189/6?u=smeijer


#6

I did silence it with the linter but i was just looking out if there is another way or somebody has written a resolver for the import plugin.


#7

Looks like there’s some work being done on this; new as of 2 days ago:

https://github.com/clayne11/eslint-import-resolver-meteor


#8

Good catch, I updated my boilerplate code to use it thanks https://github.com/trajano/meteor-boilerplate/commit/5cee306c3a11577aa63da33ddb4042f393e10136 it just needs one more tweak namely support meteor/ I opened up an issue already https://github.com/clayne11/eslint-import-resolver-meteor/issues/1


#9

Found it:

// .eslintrc
"rules": {
    "import/no-unresolved": [2, {ignore: ["^meteor/"]}],
}

#10

#11

How do you deal with imports of folders?

such as

import '/imports/startup/client';


#12

I’m not sure exactly what you’re asking. What are you expecting to happen with that statement and what is ESLint doing that is violating that expectation?


#13

I think it was an issue with absolute vs relative path…in any case it fixed itself after installing

eslint-import-resolver-meteor

Sorry for not closing not editing the comment