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

启用按需加载后报错 提示Menu is not defined #172

Open
zhi3210happy opened this issue Sep 13, 2017 · 11 comments
Open

启用按需加载后报错 提示Menu is not defined #172

zhi3210happy opened this issue Sep 13, 2017 · 11 comments

Comments

@zhi3210happy
Copy link

when I use it ,conslelog error
Menu is not defined

@sorrycc
Copy link
Member

sorrycc commented Sep 15, 2017

Please provide the code for reproduce.

@chungwong
Copy link

I do have a demo repo for the same error.
https://github.com/chungwong/babel-plugin-import-failed

clone and npm install
and you will see some component is not defined.

and antd is imported in .babelrc file

{
  "passPerPreset": true,
  "plugins": [
    "relay",
    "transform-runtime",       
    **["import", {"libraryName": "antd", "style": "css"}]**
  ],
  "presets": [
    "react",                   
    "es2015",                  
    "stage-0"
  ]
} 

@rdshoep
Copy link

rdshoep commented Oct 26, 2017

I had this problem too.

antd: 2.13.7
babel-plugin-import: 1.6.2

And I have tried to rm -rf node_modules/ && npm install,It's useless.

I found that:
1.

import {Layout} from 'antd'
const {Header, Footer, Content} = Layout

render(){
    <Layout>
        <Header></Header>
        <Content></Content>
        <Footer></Footer>
    </Layout>
}

It's OK.

import {Layout} from 'antd/lib/layout'

render(){
    <Layout>
        <Layout.Header></Layout.Header>
        <Layout.Content></Layout.Content>
        <Layout.Footer></Layout.Footer>
    </Layout>
}

It's OK.

import {Layout} from 'antd'

render(){
    <Layout>
        <Layout.Header></Layout.Header>
        <Layout.Content></Layout.Content>
        <Layout.Footer></Layout.Footer>
    </Layout>
}

It will throw error: Layout is not undefined.

@zhi3210happy
Copy link
Author

关闭webpack react生产模式核心压缩功能即不会报错。
remove these:

new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
});

@dehypnosis
Copy link

hmm. then how make antd work on NODE_ENV=production?

@JHanLu
Copy link

JHanLu commented Jan 25, 2018

@zhi3210happy 相同的情况

@yixianle
Copy link

me too!

image

After the build

image

@pascalduez
Copy link

Hi,

we encounter similar issues while running our test with coverage enabled... jest --coverage.

import { Menu } from 'antd';

const { Item } = Menu;
ReferenceError: Layout is not defined

While

import { Menu } from 'antd';

const Item = Menu.Item;
All fine...

@ghost
Copy link

ghost commented Feb 22, 2018

Did anyone resolved this Reference Error: is not defined?

I am having the same issue.

I am testing antd/antd-mobile with Meteor React Apollo server. After installing babel-plugin-import, recommended by the official doc. This error came up.

@sigarron
Copy link

got the same problem after package a win32 distribution version.
but, it seems work fine in dev-env

@sigarron
Copy link

sigarron commented Mar 13, 2018

find a way to solve this problem.
ant-design/ant-design#5060

yesmeck added a commit that referenced this issue Nov 4, 2020
Close

- #245
- #420
- #423
- #344
- #342
- #432
- #436
- #331
- #324
- #311
- #297
- #296
- #286
- #282
- #280
- #239
- #172
@yesmeck yesmeck mentioned this issue Nov 4, 2020
yesmeck added a commit that referenced this issue Nov 4, 2020
Close

- #245
- #420
- #423
- #344
- #342
- #432
- #436
- #331
- #324
- #311
- #297
- #296
- #286
- #282
- #280
- #239
- #172
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

9 participants