Compile error using the Component Lab > Autocomplete feature for SVG Icons in Material UI

﹥>﹥吖頭↗ 提交于 2020-05-26 10:52:27

问题


I got the following error when I ran my project on the browser:

Failed to compile:

./node_modules/@material-ui/lab/esm/internal/svg-icons/Close.js
Attempted import error: 'createSvgIcon' is not exported from '@material-ui/core/utils'.

I'm trying to implement the Autocomplete component (from the example in the "Multiple values" section).

Here is the code I'm using:

import React from 'react';
import Chip from '@material-ui/core/Chip';
import Autocomplete from '@material-ui/lab/Autocomplete';
import TextField from '@material-ui/core/TextField';

<Autocomplete
        multiple
        id="tags-standard"
        options={top100Films}
        getOptionLabel={(option) => option.title}
        defaultValue={[top100Films[13]]}
        renderInput={(params) => (
          <TextField
            {...params}
            variant="standard"
            label="Multiple values"
            placeholder="Favorites"
          />
        )}
      />

I tried to install SVG Icons by NPM:

npm install @material-ui/icons

And then importing them to my TypeScript:

import createSvgIcon from '@material-ui/icons/utils/createSvgIcon';

But I still have the error above. How can I resolve this issue?


回答1:


Can you try to update @material-ui/core by running

npm update



回答2:


As described in the Material-UI project CHANGELOG of the latest version (which is v4.9.9 the time I'm writing this answer), there is a change related to createSvgIcon

The complete conversation of team can be found here.

When I encountered the problem?

When running a React project and I wanted to use the Autocomplete component from @material-ui/lab.

How I solved it?

I upgraded @material-ui/core package to v4.9.9 using this command:

yarn upgrade @material-ui/core --latest



来源:https://stackoverflow.com/questions/61037522/compile-error-using-the-component-lab-autocomplete-feature-for-svg-icons-in-ma

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!