babel-plugin-module-resolver icon indicating copy to clipboard operation
babel-plugin-module-resolver copied to clipboard

Problem with jest when import from "." instead of "./index"

Open ahadyekta opened this issue 6 years ago • 4 comments

I`m using version 3.2.0 of this module. when I import a file like this in the code

import { something } from '.';

the app itself works but if I run the unit tests (jest) it will fail because it cannot import the file. If I change the "." to "./index" , tests work fine. I used another package called babel-plugin-root-import which is similar to this package and it does not have this issue.

ahadyekta avatar Nov 15 '19 05:11 ahadyekta

Update: this issue only happens if your config is like:

    ["module-resolver", {
      "root": ["./src"]
    }]

I changed it to :

    ["module-resolver", {
      "root": ["."],
      "alias": {
        "^~\/(.+)": "./src/\\1"
      }
    }]

and it fixed! So if we have some prefix it works well.

ahadyekta avatar Nov 15 '19 06:11 ahadyekta

Why not consider this a Bug ? There are many projects that use import xxx from '.' example I think babel-plugin-module-resolver should support import xxx from '.' @fatfisz

relign avatar Sep 15 '20 08:09 relign

You're most welcome to create a PR with a fix 😊

fatfisz avatar Sep 15 '20 08:09 fatfisz

You're most welcome to create a PR with a fix 😊

https://github.com/tleunen/babel-plugin-module-resolver/pull/409 😊 😊 😊

relign avatar Sep 15 '20 12:09 relign