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

Resolve local file instead of from node_modules

Open ViktorAksionov opened this issue 7 years ago • 3 comments

"babel-plugin-module-resolver": "^3.1.1"

.babelrc

{
  "presets": [
    "react-native"
  ],
  "plugins": [
    [
      "module-resolver",
      {
        "root": [
          "./src"
        ]
      }
    ],
    "relay"
  ]
}

Project file structure

src
  app
    components
       Button
       Modal
       ...

when I do import like this import {Modal} from 'react-native'; somehow I import Modal from my project instead of from 'react-native'. Why?? How to prevent babel-plugin-module-resolver to go in deep? I want only to resolve app and nothing else, so resolver should care only about import starting from app like import ... from 'app/...';

ViktorAksionov avatar Jun 10 '18 04:06 ViktorAksionov

Have you got any solution yet ! ?

Muneefm avatar Jun 25 '18 15:06 Muneefm

I ended up with removing key root and added alias like:

"alias": {
        "app": "./src/app",
         "config": "./src/config",
          ....
}

so now imports work as I expected: import Modal from 'app/components/Modal'; or import {Modal} from 'react-native'; - now plugin resolved files as it should.

Looks like root key is not mandatory and it creates issue with correct file resolving.

ViktorAksionov avatar Jun 26 '18 18:06 ViktorAksionov

@ViktorAksionov Out of curiosity, would you have a small repro project with the issue? This is the first time I hear that the root configuration is making a deep resolution...

tleunen avatar Jul 31 '18 15:07 tleunen