onebay/vite-plugin-imp

name undefined in shared.js

Closed this issue · 5 comments

Describe the bug

[ant-design-vue] get error [vite] Internal server error: Cannot read property 'name' of undefined
error in node_modules/vite-plugin-imp/dist/shared.js:55:95
const name = (_a = item) === null || _a === void 0 ? void 0 : _a.imported.name;

Libarary Info(please complete the following information):
Libarary: [vite]

  • Version [2.3.0]
    Libarary: [ant-design-vue]
  • Version [2.1.6]
    Libarary: [vite-plugin-imp]
  • Version [2.0.7]

You should show more details, such as your vite.config.js and what components you import from ant-design-vue.
Can you provide a minimal repo to reproduce this issue?

the error from:
when use antd as 'import Antd from 'ant-design-vue';'
c (don‘t have imported, so export error in share.js:55:95 const name = (_a = item) === null || _a === void 0 ? void 0 : _a.imported.name;)
Node {
type: 'ImportDefaultSpecifier',
start: 67,
end: 71,
loc: SourceLocation {
start: Position { line: 3, column: 7 },
end: Position { line: 3, column: 11 },
filename: undefined,
identifierName: undefined
},
range: undefined,
leadingComments: undefined,
trailingComments: undefined,
innerComments: undefined,
extra: undefined,
local: Node {
type: 'Identifier',
start: 67,
end: 71,
loc: SourceLocation {
start: [Position],
end: [Position],
filename: undefined,
identifierName: 'Antd'
},
range: undefined,
leadingComments: undefined,
trailingComments: undefined,
innerComments: undefined,
extra: undefined,
name: 'Antd'
}
}
when use antd as 'import { Input,Button } from 'ant-design-vue';'
share.js get item is(no error)
Node {
type: 'ImportSpecifier',
start: 75,
end: 81,
loc: SourceLocation {
start: Position {
line: 3,
column: 15
},
end: Position {
line: 3,
column: 21
},
filename: undefined,
identifierName: undefined
},
range: undefined,
leadingComments: undefined,
trailingComments: undefined,
innerComments: undefined,
extra: undefined,
imported: Node {
type: 'Identifier',
start: 75,
end: 81,
loc: SourceLocation {
start: [
Position],
end: [
Position],
filename: undefined,
identifierName: 'Button'
},
range: undefined,
leadingComments: undefined,
trailingComments: undefined,
innerComments: undefined,
extra: undefined,
name: 'Button'
},
local: Node {
type: 'Identifier',
start: 75,
end: 81,
loc: SourceLocation {
start: [
Position],
end: [
Position],
filename: undefined,
identifierName: 'Button'
},
range: undefined,
leadingComments: undefined,
trailingComments: undefined,
innerComments: undefined,
extra: undefined,
name: 'Button'
}
}

The Information you provide a little hard to read.
Maybe you should reference the demo in this repo.
For example:

import { Button, Popconfirm, message, InputNumber } from 'ant-design-vue'
export default {
name: 'AntDesignVueDemo',
components: {
Button,
Popconfirm,
InputNumber
},

And make sure your vite-plugin-imp config is same as this demo.

If you still have this issue, please provide a minimal repo to reproduce!

issue: An error occurred while importing the entire AntD library

repo

If you use default import

import Antd from 'ant-design-vue';

You don't need to use vite-plugin-imp, you just need:

import 'ant-design-vue/dist/antd.css';

Just like the antd-design-vue office document:
image

You should use vite-plugin-imp only in named import.
For example:

import { Button, message } from 'ant-design-vue';