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:

  1. upgrade to mui 5.11.0
  2. 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)

Most upvoted comments

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:

-import Grid from "@mui/material/Unstable_Grid2/Grid2"; āŒ
+import Grid from "@mui/material/Unstable_Grid2"; āœ…

-import common from '@mui/material/colors/common'; āŒ
+import * as colors from '@mui/material/colors'; āœ…
+console.log(colors.common)

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.

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.

did you fix it?

try <LocalizationProvider dateAdapter={AdapterDayjs}> <DatePicker label="Basic date picker" /> </LocalizationProvider>

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

Please make sure that you don’t have import more than 3 levels deep:

@siriwatknp - This fixed my issue. Mine was the following:

- import unsupportedProp from '@mui/material/utils/unsupportedProp';
+ import { unsupportedProp } from '@mui/material/utils';

Strangely enough, this was manifesting as the following error when I ran my test suite (adopted from MUI’s monorepo test suite)

TypeError: Unknown file extension ".jsx" for ...test.jsx
    at new NodeError (node:internal/errors:371:5)
    at Object.file: (node:internal/modules/esm/get_format:72:15)
    at defaultGetFormat (node:internal/modules/esm/get_format:85:38)
    at defaultLoad (node:internal/modules/esm/load:13:42)
    at ESMLoader.load (node:internal/modules/esm/loader:303:26)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:230:58)
    ...

We’ve always used *.test.jsx so 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 .js and ignored my eslint react/jsx-filename-extension rule I then got the following error:

.../node_modules/@mui/material/utils/unsupportedProp.js:1
import { unstable_unsupportedProp as unsupportedProp } from '@mui/utils';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    ...
    at Object.<anonymous> (.../Tooltip/Tooltip.jsx:8:1)

Sure enough, when I opened up Tooltip.jsx I realized I was importing unsupportedProp directly. 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

info  - Loaded env from /home/user/src/org/project/sub-project/app/apps/portal/.env.local
info  - Linting and checking validity of types...
info  - Creating an optimized production build...
info  - Compiled successfully
info  - Collecting page data...
/home/user/src/org/project/sub-project/app/node_modules/.pnpm/@mui+material@5.11.2_lskpmcsdi7ipu6qpuapyu56ihm/node_modules/@mui/material/styles/createTheme.js:1
import _extends from "@babel/runtime/helpers/esm/extends";
^^^^^^
SyntaxError: Cannot use import statement outside a module
    at Object.compileFunction (node:vm:352:18)
    at wrapSafe (node:internal/modules/cjs/loader:1033:15)
    at Module._compile (node:internal/modules/cjs/loader:1069:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.5568 (/home/user/src/org/project/sub-project/app/apps/portal/.next/server/pages/_app.js:506:37)
    at __webpack_require__ (/home/user/src/org/project/sub-project/app/apps/portal/.next/server/webpack-runtime.js:25:42)
> Build error occurred
Error: Failed to collect page data for /
    at /home/user/src/org/project/sub-project/app/node_modules/.pnpm/next@13.1.1_7xlrwlvvs7cv2obrs6a5y6oxxq/node_modules/next/dist/build/utils.js:960:15
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  type: 'Error'
}
 ELIFECYCLE  Command failed with exit code 1.
ERROR: command finished with error: command (/home/user/src/org/project/sub-project/app/apps/portal) pnpm run build exited (1)

I had a very similar error with the import of Unstable_Grid2 which I believe is connected to this issue:

Details:

    /Users/redacted/Documents/Progetti/redacted/redacted/node_modules/@mui/material/Unstable_Grid2/Grid2.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import PropTypes from 'prop-types';
                                                                                      ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      10 | import { useEffect, useState } from "react";
      11 | import { useParams } from "react-router-dom";
    > 12 | import Grid from "@mui/material/Unstable_Grid2/Grid2";

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.17 for now