Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not compatible with babel-plugin-transform-imports #136

Open
joncursi opened this issue Jul 7, 2020 · 2 comments
Open

Not compatible with babel-plugin-transform-imports #136

joncursi opened this issue Jul 7, 2020 · 2 comments

Comments

@joncursi
Copy link

joncursi commented Jul 7, 2020

I want to use this module along with babel-plugin-transform-imports so that I can map both internal and external import paths. However, this plugin causes babel-plugin-transform-imports to stop functioning.

E.g.:

    [
      'babel-plugin-root-import',
      {
        rootPathPrefix: '~',
        rootPathSuffix: './src',
      },
    ],
    [
      'babel-plugin-transform-imports',
      {
        '~/components': {
          preventFullImport: true,
          transform: '~/components/${member}',
        },
        '@material-ui/core': {
          preventFullImport: true,
          transform: '@material-ui/core/${member}',
        },
        lodash: {
          preventFullImport: true,
          transform: 'lodash/${member}',
        },
    ],

In the built files, ~ is appropriately mapped for internal modules, however it is as if babel-plugin-transform-imports never ran (built files are still using named imports).

@enigma1
Copy link

enigma1 commented Oct 22, 2020

Have you tried changing the plugins order? Having the babel-plugin-transform-imports first.

@aquintiliano
Copy link

aquintiliano commented May 11, 2021

I am doing something similar here and also getting the problem, but I'm using @babel/plugin-transform-react-jsx instead

my code:

  {
    "plugins": [
      [
        "@babel/plugin-transform-react-jsx",
        {
          "runtime": "automatic",
          "importSource": "#/runtime"
        }
      ],
      [
        "babel-plugin-root-import", 
        {
          "paths": [
            {
              "rootPathSuffix": "./src",
              "rootPathPrefix": "~/"
            },
            {
              "rootPathSuffix": "./",
              "rootPathPrefix": "#/"
            }
          ]
        }
      ]
    ]
  }

I already tried inverting the order

but on final file, it tries to import from #/runtime instead of ../../runtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants