question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Configuring on babel.config.js?

See original GitHub issue

I’m relatively new to Expo and React Native. Have been facing problems in using absolute paths while importing the modules. Was reading on how to implement this plugin but I am unable to use it properly since it has only instructions for .babelrc. I did almost everything found on different threads regarding this but still, I am unable to use it properly. In my expo project, I also do not have any .babelrc file instead I have babel.config.js file.

I am trying to convert this code for .babelrc:

{
  "presets": ["babel-preset-expo"],
  "env": {
    "development": {
      "plugins": [
        "transform-react-jsx-source",
        ["module-resolver", {
          "root": ["./src"]
        }]
      ]
    }
  }
}

To this for babel.config.js:

module.exports = function(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
  };
};

Thanks

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:15
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

27reactions
ethansharcommented, Mar 15, 2020

it’s important to reset cache after configuring new aliases just run react-native start --resetCache The new alias should take affect after that.

7reactions
ChiuMungZitAlexandercommented, Jan 21, 2019

@wlopz

It works for me in this way. Try it out.

function config(api) {
  api.cache(true);
  return {
    presets: ['babel-preset-expo'],
    env: {
      development: {
        plugins: [
          ['module-resolver', {
            root: ['./src'],
            alias: {
              '~components': './src/components',
            },
          }],
        ],
      },
    },
  };
}

That ~ is necessary. But when import modules, you don’t need that ~, and still use import * from 'components'.

I haven’t studied the source code, I cannot give exact why…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configure Babel
Create a file called babel.config.json with the following content at the root of your project (where the package.json is). ... Check out the...
Read more >
When to use babel.config.js and .babelrc - Stack Overflow
Also, some other times babel configuration files are downright ignored, as in the case of webpack and babel-loader. You'd expect babel to load ......
Read more >
Advanced Features: Customizing Babel Config - Next.js
To start, you only need to define a .babelrc file (or babel.config.js ) at the top of your app. If such a file...
Read more >
Adding custom babel configuration to your project - WPACK.IO
If you need shared babel config between @wpackio/scripts and some other tool, then create a babel.config.js file in the your project root. ......
Read more >
How to Setup Babel in Node.js - freeCodeCamp
Let's setup a basic Node app which we will use for this tutorial. Create a new folder. For this tutorial, I'll call mine...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found