Babel-plugin-module-resolver: Needs better documentation for config

Created on 24 Sep 2017  路  8Comments  路  Source: tleunen/babel-plugin-module-resolver

In my package.json, I had this:

    "module-resolver",
    {
      "root": [ "./src", "node_modules" ],
      "alias": {
        "@alc": "alc",
        "@lib": "lib",
        "@fixture": "__fixture__",
        "@languages": "languages"
      }
    }

This broke other modules that depended on a global variable 'process'. I don't know where that's defined. When I replaced "root" with

      "root": [ "./src" ],

then the broken modules worked again.

Previously, I had it defined as:

    "module-resolver",
    {
      "root": ["."],
      "alias": {
        "@src": "src",
        "@fixture": "src/__fixture__"
      }
    }

This broke my own app in many places.

I had to discover what works by trial and error.

I really like this plugin when I get it working, but there's too many gotchas.

I opened a related issue here: https://github.com/visionmedia/debug/issues/511#issuecomment-331683958 before I realized that the problem originated with this plugin.

I wish someone could document this better. I would do so myself and submit a PR, but I don't know why my previous config was wrong so I don't know what to tell people to avoid.

enhancement help wanted

Most helpful comment

Hey, from reading the docs it's not obvious what's root option used for. It'll be great to have some examples of usage. Thank you.

All 8 comments

Defining node_modules as a root is useless because it's already the default behavior. Otherwise you're right and it seems some people have an issue with a root of .. To be honest, I don't know why and this would require investigation.

But overall, I'd appreciate any help for improving the plugin and its documentation.

In my setup, Webpack invokes the babel transpiler through the plugin "babel-loader". So babel is really inheriting its run-time environment from the webpack plugin. This might be the first place I'd look for a problem, if I had sufficient time to investigate this.

Thanks for your response.

If you see something that could be improved in the doc. Please let us know what exactly and/or open a pull request.

I'm pretty slammed right now, so it's on a back burner. Thanks for your attention to this.

Hey, from reading the docs it's not obvious what's root option used for. It'll be great to have some examples of usage. Thank you.

I was thinking, maybe having an "examples" dir would help? It works nicely for next.js.

We tried to improve the documentation. Thanks to @gsouquet.
You can access the new doc here: https://github.com/tleunen/babel-plugin-module-resolver/blob/master/DOCS.md

Let us know if you still have troubles understanding how to use the plugin

I have this config,
my app name in package.json is "app":

{
  "name": "rnapp",
  "version": "0.1.0",
  "private": true,
...

and App.js

```import React from 'react'
import { Provider } from 'react-redux'
import store from 'rnskeleton/store'

import AppNavigator from 'rnapp/src/components/Navigator' // works
import AppNavigator from '@components/Navigator' // doesn't work

const App = () => (


)

export default App```

{ "presets": ["babel-preset-expo", "react-native", "react-native-dotenv"], "env": { "development": { "plugins": [ "transform-react-jsx-source", "transform-react-pug", "transform-react-jsx" ] } }, "plugins":[ [ "module-resolver", { "alias": { "cwd": ".", "src": "./src", "@components": "./src/components/", "screens": "./src/screens" } } ] ] }

Was this page helpful?
0 / 5 - 0 ratings

Related issues

liemdo picture liemdo  路  6Comments

dschinkel picture dschinkel  路  4Comments

ELI7VH picture ELI7VH  路  3Comments

ViktorAksionov picture ViktorAksionov  路  3Comments

wlopz picture wlopz  路  7Comments