material-ui: SyntaxError: Unexpected token 'export' when upgrading to 5.11.0
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Steps to reproduce š¹
Link to live example:
Steps:
- upgrade to mui 5.11.0
- run jest test
yarn test
Current behavior šÆ
By default ānode_modulesā folder is ignored by transformers.
Here's what you can do:
⢠If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
⢠If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
⢠To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
⢠If you need a custom transformation specify a "transform" option in your config.
⢠If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.
You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation
Details:
/Users/carlosagosto/projectName/node_modules/@mui/material/colors/common.js:5
export default common;
^^^^^^
SyntaxError: Unexpected token 'export'
> 2 | import common from '@mui/material/colors/common';
Expected behavior š¤
Same as what was happening with version 5.10.17 jest test should pass because I am amazing! š
Context š¦
Trying to get jest test to run with out have issue with the mui package. Look to be an issue with @mui/material/colors
Your environment š
npx @mui/envinfo
Don't forget to mention which browser you used.
System:
OS: macOS 13.0.1
Binaries:
Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
Yarn: 1.22.15 - /usr/local/bin/yarn
npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
Browsers:
Chrome: 108.0.5359.98
Edge: 108.0.1462.46
Firefox: 103.0.2
Safari: 16.1
npmPackages:
@emotion/react: ^11.10.5 => 11.10.5
@emotion/styled: ^11.10.5 => 11.10.5
@mui/base: 5.0.0-alpha.109
@mui/core-downloads-tracker: 5.10.17
@mui/icons-material: ^5.11.0 => 5.11.0
@mui/lab: ^5.0.0-alpha.112 => 5.0.0-alpha.112
@mui/material: ^5.10.17 => 5.10.17
@mui/private-theming: 5.10.16
@mui/styled-engine: 5.10.16
@mui/system: 5.10.17
@mui/types: 7.2.2
@mui/utils: 5.10.16
@mui/x-date-pickers: ^5.0.10 => 5.0.10
@types/react: ^18.0.26 => 18.0.26
react: ^18.2.0 => 18.2.0
react-dom: ^18.2.0 => 18.2.0
typescript: ^4.9.4 => 4.9.4
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 24 (5 by maintainers)
I have an issue with
SyntaxError: Unexpected token āexportā
import { DemoContainer } from ā@mui/x-date-pickers/internals/demoā import { AdapterMoment } from ā@mui/x-date-pickers/AdapterMomentā import { LocalizationProvider } from ā@mui/x-date-pickers/LocalizationProviderā import { DatePicker } from ā@mui/x-date-pickers/DatePickerā
it seams like itās the problem with x-date-pickers, but I tried all, reinstalled the package, still have this error.
duplicate #35480
@matannahmani @adamsujeta Please make sure that you donāt have import more than 3 levels deep:
For more details, see https://github.com/mui/material-ui/issues/35480#issuecomment-1354334459.
try
<LocalizationProvider dateAdapter={AdapterDayjs}> <DatePicker label="Basic date picker" /> </LocalizationProvider>I donāt think this should be closed. It seems like you found a workaround, but the issue is still there, at least until it is stated somewhere that we should change the way we import stuff.
did you fix it?
Yep, that did the trick. If you donāt really need a DemoContainer then you need not use it and it should work! Other than that, I still do not have a solution for the Unexpected token error
BUMP ^^ still exists on nextjs
Just tested and this is still happening in v5.11.2
@siriwatknp - This fixed my issue. Mine was the following:
Strangely enough, this was manifesting as the following error when I ran my test suite (adopted from MUIās monorepo test suite)
Weāve always used
*.test.jsxso it was weird this randomly started happening when I upgraded to anything beyond v5.11.x. To try and get past the error, I renamed the file to.jsand ignored my eslintreact/jsx-filename-extensionrule I then got the following error:Sure enough, when I opened up
Tooltip.jsxI realized I was importingunsupportedPropdirectly. When I made the adjustment mentioned at the beginning of this rant and returned everything back the way it was my test suite ran just fine and everything is working agian.Same, I tried 5.10.17 and it works fine but the below error shows up when using 5.11.0, 5.11.1, 5.11.2
I had a very similar error with the import of
Unstable_Grid2which I believe is connected to this issue:Unfortunately I have no time to dig into the issue or to create a repo which reproduces the issue, but I thought it was worth reporting.
Reverted to
5.10.17for now