admin管理员组文章数量:1277885
Heeey, My question is the following:
I have this project, made with NextJS + React with node. Straight to the point, my app works well, except when reloading a page with a Select from Material UI. The code that matters in that page is:
<Select defaultValue='#' onChange={e => setCommunityCode(e.target.value)} labelId='munityLabel'>
<MenuItem value='#' hidden={true}></MenuItem>
{munities.map(munity => (
<MenuItem value={munity.id} key={munity.id}>
{munity.id + ' - ' + munity.name}
</MenuItem>
))}
</Select>
Now, my page works great, up until pressing F5 or reloading the page with the "Relaod" button of my browser. Then, it show the following message:
"SyntaxError: Cannot use import statement outside a module". If I start digging (not much though) it appears the error es from a dependency from node_modules, it being from @mui/material and being Select.
The way I import Select is:
import Select from '@mui/material/Select/Select';
The image showing the error
Heeey, My question is the following:
I have this project, made with NextJS + React with node. Straight to the point, my app works well, except when reloading a page with a Select from Material UI. The code that matters in that page is:
<Select defaultValue='#' onChange={e => setCommunityCode(e.target.value)} labelId='munityLabel'>
<MenuItem value='#' hidden={true}></MenuItem>
{munities.map(munity => (
<MenuItem value={munity.id} key={munity.id}>
{munity.id + ' - ' + munity.name}
</MenuItem>
))}
</Select>
Now, my page works great, up until pressing F5 or reloading the page with the "Relaod" button of my browser. Then, it show the following message:
"SyntaxError: Cannot use import statement outside a module". If I start digging (not much though) it appears the error es from a dependency from node_modules, it being from @mui/material and being Select.
The way I import Select is:
import Select from '@mui/material/Select/Select';
The image showing the error
Share Improve this question asked Sep 10, 2022 at 18:23 khandoraskhandoras 651 silver badge4 bronze badges2 Answers
Reset to default 8You're not importing Select properly . Do this instead :
import Select from '@mui/material/Select';
// or
import { Select } from '@mui/material';
MUI v5, Grid2 ponent, for me solved in this way:
incorrect:
import Grid from "@mui/material/Unstable_Grid2/Grid2";
correct:
import Grid from "@mui/material/Unstable_Grid2";
本文标签: javascriptMaterial UI cannot use import statement outside a moduleSelect dependencyStack Overflow
版权声明:本文标题:javascript - Material UI: cannot use import statement outside a module - Select dependency - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741271387a2369368.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论