tleunen / babel-plugin-module-resolver

Custom module resolver plugin for Babel
MIT License
3.45k stars 204 forks source link

Resolve local file instead of from node_modules #299

Open ViktorAksionov opened 6 years ago

ViktorAksionov commented 6 years ago

"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/...';

Muneefm commented 6 years ago

Have you got any solution yet ! ?

ViktorAksionov commented 6 years ago

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.

tleunen commented 6 years ago

@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...