1

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

1 Answer 1

3

Check the configuration:

.babelrc

{
  "extends": "./babel.config.js"
}

babel.config.js

module.exports = (api) => {
  api.cache(true)
  return {
    "env": {
      "development": {
        "plugins": [
          "transform-react-jsx-source",
          ["module-resolver", {
            "root": ["./src"]
          }]
        ]
      }
    },
    presets: ['babel-preset-expo']
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Where should .babelrc and babel.config.js files be located? And does babel.config.js need to be referenced/linked anywhere?
Usually in the root of your project, for more details check the official documentation babeljs.io/docs/en/config-files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.