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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: [Babel standalone import error] #13747

Open
1 task
letanloc1998 opened this issue Sep 11, 2021 · 2 comments 路 May be fixed by #16045
Open
1 task

[Bug]: [Babel standalone import error] #13747

letanloc1998 opened this issue Sep 11, 2021 · 2 comments 路 May be fixed by #16045

Comments

@letanloc1998
Copy link

letanloc1998 commented Sep 11, 2021

馃捇

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

I using Babel standalone with React. I can't import same js name component (different URL).

...
<script src='src/lib/react/17.0.2/react.production.min.js'></script>
<script src='src/lib/react-dom/17.0.2/react-dom.production.min.js'></script>
<script src='src/lib/react-router-dom/5.2.0/react-router-dom.min.js'></script>
<script src='src/lib/babel/standalone/7.15.3/babel.min.js'></script>
...
<script>
    Babel.registerPreset("config-preset", {
        presets: [
            [Babel.availablePresets["es2017"], { modules: true }],
            [Babel.availablePresets["react"]]
        ],
        plugins: [
            [Babel.availablePlugins["transform-modules-umd"]]
        ]
    });
</script>
...
<script type="text/babel" data-presets="config-preset" src="src/pages/Home/index.js"></script>
<script type="text/babel" data-presets="config-preset" src="src/pages/Login/index.js"></script>
...
<script type="text/babel" data-presets="config-preset" src="src/routes/index.js"></script>
...

routes-index.js

import Home from "../pages/Home/index.js";
import Login from "../pages/Login/index.js";

I using console.log(<Home />) and console.log(<Login />) and see Babel generate by name of JS file. So, if I import components with same name, babel will generate index.Home, index2.Login => ERROR.
I must change file name to fix this case

<script type="text/babel" data-presets="config-preset" src="src/pages/Home/pages-home-index.js"></script>
<script type="text/babel" data-presets="config-preset" src="src/pages/Login/pages-login-index.js"></script>

routes-index.js

import Home from "../pages/Home/pages-home-index.js";
import Login from "../pages/Login/pages-login-index.js";

I think you need change the way to generate import file, and it's better if I have some config to auto import index.js (I want to babel auto check and find index.js <script type="text/babel" data-presets="config-preset" src="src/pages/Home/index.js"></script> => <script type="text/babel" data-presets="config-preset" src="src/pages/Home"></script>

Thank you a lot.

Configuration file name

No response

Configuration

No response

Current and expected behavior

I want to import without error

import Home from "../pages/Home/index.js";
import Login from "../pages/Login/index.js";

Environment

Babel standalone version 7.15.3

Possible solution

Change the way to generate import object (full url instead only file name)

It's better if you add feature allow config auto import index.js if find url fail or alway find index.js if suffix isn't js file

Additional context

No response

@babel-bot
Copy link
Collaborator

Hey @letanloc1998! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

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

Successfully merging a pull request may close this issue.

2 participants