Reputation: 835
I have this problematic import.
import * as Collection from '../../lib/collection.js'
root
> lib
>> collection.js
> tests
>> folder1
>>> collection.spec.js
how can resolve this relative path with something like
import * as Collection from '@/lib/collection.js'
OR
import * as Collection from 'lib/collection.js'
tried both. neither worked.
any ideas?
Upvotes: 1
Views: 1412
Reputation: 733
I’m not sure what you mean when you say “problematic”, as that import looks correct/like it should work fine. Is it not working for you?
If your concern is that you’d rather avoid having to go up directories with ../
leading to the two options you tried, and you’re trying to get something like that to work, that’s addressed better than I could elsewhere such as this accepted answer about what @ does and the others. Short answers:
lib/collection.js
isn’t relative, and would refer to a package (see also Node’s doc on import specifiers@/lib/collection.js
isn’t a natively supported JavaScript syntax and requires a module loader/bundler, but should work once set up.Upvotes: 1