babel-plugin-root-import icon indicating copy to clipboard operation
babel-plugin-root-import copied to clipboard

unable to find '.../.../.../src'

Open Tycholiz opened this issue 4 years ago • 7 comments

I have babel.config.js:

module.exports = function(api) {
  api.cache(true)

  return {
    plugins: [
      [
        'babel-plugin-root-import',
        {
          root: __dirname,
          rootPathSuffix: 'src',
          rootPathPrefix: '~/'
        }
      ]
    ],
    presets: ['module:metro-react-native-babel-preset'],
  }
}

but am having issues loading modules with ~. From src/components/organisms/Categories.js, I try to import api from '~/services/api'.

What could I possibly be missing here?

Tycholiz avatar Dec 09 '19 06:12 Tycholiz

I'm facing the same issue.

koka0012 avatar Dec 11 '19 16:12 koka0012

Without the metro-react-native preset, I get this as babel output, which looks good:

import api from "../../services/api";

and with it, I get this, which also appears to be correct, as long as @babel/runtime is available.

var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");
var _api=_interopRequireDefault(require("../../services/api"));

Maybe something else happens when actually executed by the react-native build tools, but I'm not very familiar with it. Any more information you can provide, like the full error message?

brigand avatar Dec 11 '19 17:12 brigand

Any updates on this? I'm getting the same issue as well

jschlachtenhaufen avatar Jun 27 '20 22:06 jschlachtenhaufen

same as well

nitpum avatar Jul 30 '20 08:07 nitpum

same here ;/

zTaaso avatar Aug 18 '20 02:08 zTaaso

Have you tried the static babel config and seeing the same problem. I am seeing such issues when I try it with babel.config.js and a test package but not when using the static .babelrc configuration. https://babeljs.io/docs/en/config-files#config-function-api You should check whether the the babel.config.js really takes place

enigma1 avatar Nov 13 '20 11:11 enigma1

I'm using .babelrc and works ok.

DracotMolver avatar Nov 19 '20 00:11 DracotMolver