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

import { Component } from 'antd' does not work. #204

Open
eminx opened this issue Jan 24, 2018 · 12 comments
Open

import { Component } from 'antd' does not work. #204

eminx opened this issue Jan 24, 2018 · 12 comments

Comments

@eminx
Copy link

eminx commented Jan 24, 2018

The plugin imports don't seem to work.

In my code: import { Layout } from 'antd';

It gives the error: ReferenceError: Layout is not defined.

When I change my code to: const Layout = require('antd').Layout;

it works.

Can someone please help me fix that? This started out of nothing...

@eminx eminx changed the title Imports - { Component } from 'antd' does not work. import { Component } from 'antd' does not work. Jan 24, 2018
@eminx
Copy link
Author

eminx commented Jan 25, 2018

No one out there? :(

@yesmeck
Copy link
Contributor

yesmeck commented Jan 31, 2018

Reproduce repo.

@eminx
Copy link
Author

eminx commented Feb 2, 2018

https://github.com/eminx/Nodal

See the importing of antd components are with /lib at the end. This was the fix I could do. Like this:

import { Button } from 'antd/lib';

If you want to reproduce, just remove the /lib and you'll see...

Thanks!

@eminx
Copy link
Author

eminx commented Feb 2, 2018

@lefter
Copy link

lefter commented Feb 22, 2018

update your react and react-dom 16 +

@ghost
Copy link

ghost commented Feb 22, 2018

react and react-dom are all 16.2.0. But I also have the same Reference Error of any Component I tried to use.

Probably Meteor and babel-plugin-import is not compatible for some reason. As I see @eminx is using Meteor framework also.

@eminx
Copy link
Author

eminx commented Feb 27, 2018

Exactly. @gchansc Do you also use meteor? In that case it must be related to it. The weird thing is everything was working fine in the beginning. This all happened at some ambiguous point. Fortunately I found the work around with /lib at the end though...

@ghost
Copy link

ghost commented Feb 27, 2018

@eminx Yes. I'm testing Meteor with antd. Then I ran into this issue. Seems the current workaround is to add /lib when import.

Happy coding! ^^

@cloudever
Copy link

It's clear that problem with meteor builder. Try to build client code separetely on your host and give us feedback.

@eminx
Copy link
Author

eminx commented Mar 13, 2018

Since this is an issue that has to do with Meteor, and not antd, I'm closing it.

@eminx
Copy link
Author

eminx commented Feb 6, 2021

Hello!

After almost three years I'm reopening the same issue :)

Basically I get why we need to do the /lib hack: Because we have the .babelrc file defined with this configuration for treeshaking:

{
  "presets": ["meteor"],
  "plugins": [
    ["import", { "libraryName": "antd", "style": true }, "antd"],
    [
      "import",
      {
        "libraryName": "@ant-design/icons",
        "libraryDirectory": "lib/icons",
        "camel2DashComponentName": false
      },
      "@ant-design/icons"
    ]
  ]
}

But unfortunately the treeshaking itself is not working. Because well, I'm using only a few icons and it seems like they are over 1mb in the bundle!

How to make this tree-shaking work on Meteor so the bundle is for humans?

Screenshot 2021-02-06 at 02 36 16

@designervoid
Copy link

designervoid commented Aug 2, 2021

with vite and vue3 (with typescript) working import like that:

import { createApp } from "vue";
import App from "./App.vue";
import Antd from "ant-design-vue";
import "ant-design-vue/dist/antd.css";
const app = createApp(App);
// components
app.use(Antd);

// mount
app.mount('#app');

with webpack and vue3 (with typescript) working import like that:

import { createApp } from "vue";
import App from "./App.vue";
import Antd from "ant-design-vue/lib";
import "ant-design-vue/dist/antd.css";
const app = createApp(App);
// components
app.use(Antd);

// mount
app.mount('#app');

UPD:
Need to configure babel-plugin-import and you can use only “ant-design-vue” path.

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

5 participants