6

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='communityLabel'>
   <MenuItem value='#' hidden={true}></MenuItem>
      {communities.map(community => (
          <MenuItem value={community.id} key={community.id}>
             {community.id + ' - ' + community.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 comes 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

2 Answers 2

8

You're not importing Select properly . Do this instead :

import Select from '@mui/material/Select';
// or
import { Select } from '@mui/material';
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! Visual Studio code was showing me an incorrect import, and I didn't check if it was completely ok.
So it has nothing to do with the import statement ?
Yes, it was the import statement! Thank you very much!
5

MUI v5, Grid2 component, for me solved in this way:

incorrect:

import Grid from "@mui/material/Unstable_Grid2/Grid2";

correct:

import Grid from "@mui/material/Unstable_Grid2";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.