Lucas Ramos
Lucas Ramos

Reputation: 5

SPFx and Material React Table Error You may need an appropriate loader to handle this file type (fresh installation)

I'm trying to use Material React Table in a fresh installation of SPFx created with:

yo @microsoft/sharepoint

After SPFx installation I install Material React Table with:

npm i material-react-table @mui/material @mui/x-date-pickers @mui/icons-material @emotion/react @emotion/styled

After that, I create a component that implements Material React Table, according to their page Material React Table - Basic example. My component looks like this:

import * as React from 'react';

import { useMemo } from 'react';
import {
  MaterialReactTable,
  useMaterialReactTable,
  type MRT_ColumnDef,
} from 'material-react-table';

//example data type
type Person = {
    name: {
      firstName: string;
      lastName: string;
    };
    address: string;
    city: string;
    state: string;
};

const data: Person[] = [
    {
      name: {
        firstName: 'John',
        lastName: 'Doe',
      },
      address: '261 Erdman Ford',
      city: 'East Daphne',
      state: 'Kentucky',
    },
    {
      name: {
        firstName: 'Jane',
        lastName: 'Doe',
      },
      address: '769 Dominic Grove',
      city: 'Columbus',
      state: 'Ohio',
    },
    {
      name: {
        firstName: 'Joe',
        lastName: 'Doe',
      },
      address: '566 Brakus Inlet',
      city: 'South Linda',
      state: 'West Virginia',
    },
    {
      name: {
        firstName: 'Kevin',
        lastName: 'Vandy',
      },
      address: '722 Emie Stream',
      city: 'Lincoln',
      state: 'Nebraska',
    },
    {
      name: {
        firstName: 'Joshua',
        lastName: 'Rolluffs',
      },
      address: '32188 Larkin Turnpike',
      city: 'Omaha',
      state: 'Nebraska',
    },
];

export const App: React.FunctionComponent<{}> = () => {
    const columns = useMemo<MRT_ColumnDef<Person>[]>(
        () => [
          {
            accessorKey: 'name.firstName', //access nested data with dot notation
            header: 'First Name',
            size: 150,
          },
          {
            accessorKey: 'name.lastName',
            header: 'Last Name',
            size: 150,
          },
          {
            accessorKey: 'address', //normal accessorKey
            header: 'Address',
            size: 200,
          },
          {
            accessorKey: 'city',
            header: 'City',
            size: 150,
          },
          {
            accessorKey: 'state',
            header: 'State',
            size: 150,
          },
        ],
        [],
    );

    const table = useMaterialReactTable({
        columns,
        data, //data must be memoized or stable (useState, useMemo, defined outside of this component, etc.)
    });

    return (
        <MaterialReactTable table={table} />
    )
}

And after compiling the App with this component I get this error:

Error - [webpack] 'dist':
./node_modules/@mui/x-date-pickers/internals/utils/views.js 13:34
Module parse failed: Unexpected token (13:34)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|   defaultViews
| }) => {
>   const viewsWithDefault = views ?? defaultViews;
|   let openToWithDefault;
|   if (openTo != null) {
 @ ./node_modules/@mui/x-date-pickers/internals/utils/date-utils.js 1:0-40 97:6-19 100:6-19 103:6-19 106:6-19 109:6-19
 @ ./node_modules/@mui/x-date-pickers/TimePicker/TimePickerToolbar.js
 @ ./node_modules/@mui/x-date-pickers/TimePicker/index.js
 @ ./node_modules/material-react-table/dist/index.esm.js
 @ ./lib/webparts/testTablaMui/components/App.js
 @ ./lib/webparts/testTablaMui/components/TestTablaMui.js
 @ ./lib/webparts/testTablaMui/TestTablaMuiWebPart.js

./node_modules/@tanstack/virtual-core/dist/esm/index.js 241:51
Module parse failed: Unexpected token (241:51)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     this.notify = (force, sync) => {
|       var _a, _b;
>       const { startIndex, endIndex } = this.range ?? {
|         startIndex: void 0,
|         endIndex: void 0
 @ ./node_modules/@tanstack/react-virtual/dist/esm/index.js 3:0-164 4:0-39 4:0-39 21:14-25 34:4-22 35:4-24 36:16-29 43:24-41 44:26-45 45:16-28
 @ ./node_modules/material-react-table/dist/index.esm.js
 @ ./lib/webparts/testTablaMui/components/App.js
 @ ./lib/webparts/testTablaMui/components/TestTablaMui.js
 @ ./lib/webparts/testTablaMui/TestTablaMuiWebPart.js

./node_modules/@mui/x-date-pickers/DateTimePicker/DateTimePickerToolbar.js 247:39
Module parse failed: Unexpected token (247:39)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|   const translations = usePickersTranslations();
|   const classes = useUtilityClasses(ownerState);
>   const toolbarTitle = inToolbarTitle ?? translations.dateTimePickerToolbarTitle;
|   const formatHours = time => ampm ? utils.format(time, 'hours12h') : utils.format(time, 'hours24h');
|   const dateText = React.useMemo(() => {
 @ ./node_modules/@mui/x-date-pickers/DateTimePicker/index.js 4:0-64 4:0-64
 @ ./node_modules/material-react-table/dist/index.esm.js
 @ ./lib/webparts/testTablaMui/components/App.js
 @ ./lib/webparts/testTablaMui/components/TestTablaMui.js
 @ ./lib/webparts/testTablaMui/TestTablaMuiWebPart.js

./node_modules/@mui/x-date-pickers/DesktopDateTimePicker/DesktopDateTimePickerLayout.js 27:67
Module parse failed: Unexpected token (27:67)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     classes
|   } = props;
>   const isActionBarVisible = actionBar && (actionBar.props.actions?.length ?? 0) > 0;
|   const ownerState = _extends({}, props, {
|     isRtl
 @ ./node_modules/@mui/x-date-pickers/DesktopDateTimePicker/index.js 2:0-76 2:0-76
 @ ./node_modules/@mui/x-date-pickers/DateTimePicker/DateTimePicker.js
 @ ./node_modules/@mui/x-date-pickers/DateTimePicker/index.js
 @ ./node_modules/material-react-table/dist/index.esm.js
 @ ./lib/webparts/testTablaMui/components/App.js
 @ ./lib/webparts/testTablaMui/components/TestTablaMui.js
 @ ./lib/webparts/testTablaMui/TestTablaMuiWebPart.js

./node_modules/@mui/x-date-pickers/LocalizationProvider/LocalizationProvider.js 32:50
Module parse failed: Unexpected token (32:50)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     utils: parentUtils,
|     localeText: parentLocaleText
>   } = React.useContext(MuiPickersAdapterContext) ?? {
|     utils: undefined,
|     localeText: undefined
 @ ./node_modules/@mui/x-date-pickers/internals/hooks/useUtils.js 3:0-91 6:40-64
 @ ./node_modules/@mui/x-date-pickers/TimePicker/TimePickerToolbar.js
 @ ./node_modules/@mui/x-date-pickers/TimePicker/index.js
 @ ./node_modules/material-react-table/dist/index.esm.js
 @ ./lib/webparts/testTablaMui/components/App.js
 @ ./lib/webparts/testTablaMui/components/TestTablaMui.js
 @ ./lib/webparts/testTablaMui/TestTablaMuiWebPart.js

./node_modules/@mui/x-date-pickers/internals/hooks/date-helpers-hooks.js 33:47
Module parse failed: Unexpected token (33:47)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|   const handleMeridiemChange = React.useCallback(mode => {
|     const timeWithMeridiem = date == null ? null : convertToMeridiem(date, mode, Boolean(ampm), utils);
>     onChange(timeWithMeridiem, selectionState ?? 'partial');
|   }, [ampm, date, onChange, selectionState, utils]);
|   return {
 @ ./node_modules/@mui/x-date-pickers/TimePicker/TimePickerToolbar.js 16:0-72 141:6-21
 @ ./node_modules/@mui/x-date-pickers/TimePicker/index.js
 @ ./node_modules/material-react-table/dist/index.esm.js
 @ ./lib/webparts/testTablaMui/components/App.js
 @ ./lib/webparts/testTablaMui/components/TestTablaMui.js
 @ ./lib/webparts/testTablaMui/TestTablaMuiWebPart.js

./node_modules/@mui/x-date-pickers/MobileTimePicker/MobileTimePicker.js 37:52
Module parse failed: Unexpected token (37:52)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     seconds: renderTimeViewClock
|   }, defaultizedProps.viewRenderers);
>   const ampmInClock = defaultizedProps.ampmInClock ?? false;
|
|   // Props with the default values specific to the mobile variant
 @ ./node_modules/@mui/x-date-pickers/MobileTimePicker/index.js 1:0-54 1:0-54
 @ ./node_modules/@mui/x-date-pickers/TimePicker/TimePicker.js
 @ ./node_modules/@mui/x-date-pickers/TimePicker/index.js
 @ ./node_modules/material-react-table/dist/index.esm.js
 @ ./lib/webparts/testTablaMui/components/App.js
 @ ./lib/webparts/testTablaMui/components/TestTablaMui.js
 @ ./lib/webparts/testTablaMui/TestTablaMuiWebPart.js

./node_modules/@mui/x-date-pickers/MobileDateTimePicker/MobileDateTimePicker.js 41:52
Module parse failed: Unexpected token (41:52)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     seconds: renderTimeViewClock
|   }, defaultizedProps.viewRenderers);
>   const ampmInClock = defaultizedProps.ampmInClock ?? false;
|
|   // Props with the default values specific to the mobile variant
 @ ./node_modules/@mui/x-date-pickers/MobileDateTimePicker/index.js 1:0-62 1:0-62
 @ ./node_modules/@mui/x-date-pickers/DateTimePicker/DateTimePicker.js
 @ ./node_modules/@mui/x-date-pickers/DateTimePicker/index.js
 @ ./node_modules/material-react-table/dist/index.esm.js
 @ ./lib/webparts/testTablaMui/components/App.js
 @ ./lib/webparts/testTablaMui/components/TestTablaMui.js
 @ ./lib/webparts/testTablaMui/TestTablaMuiWebPart.js

./node_modules/@mui/x-date-pickers/DesktopDatePicker/DesktopDatePicker.js 43:47
Module parse failed: Unexpected token (43:47)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     viewRenderers,
|     format: resolveDateFormat(utils, defaultizedProps, false),
>     yearsPerRow: defaultizedProps.yearsPerRow ?? 4,
|     slots: _extends({
|       openPickerIcon: CalendarIcon,
 @ ./node_modules/@mui/x-date-pickers/DesktopDatePicker/index.js 1:0-56 1:0-56
 @ ./node_modules/@mui/x-date-pickers/DatePicker/DatePicker.js
 @ ./node_modules/@mui/x-date-pickers/DatePicker/index.js
 @ ./node_modules/material-react-table/dist/index.esm.js
 @ ./lib/webparts/testTablaMui/components/App.js
 @ ./lib/webparts/testTablaMui/components/TestTablaMui.js
 @ ./lib/webparts/testTablaMui/TestTablaMuiWebPart.js

./node_modules/@mui/x-date-pickers/DesktopTimePicker/DesktopTimePicker.js 46:52
Module parse failed: Unexpected token (46:52)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     meridiem: renderTimeView
|   }, defaultizedProps.viewRenderers);
>   const ampmInClock = defaultizedProps.ampmInClock ?? true;
|   const actionBarActions = shouldRenderTimeInASingleColumn ? [] : ['accept'];
|   // Need to avoid adding the `meridiem` view when unexpected renderer is specified
 @ ./node_modules/@mui/x-date-pickers/DesktopTimePicker/index.js 1:0-56 1:0-56
 @ ./node_modules/@mui/x-date-pickers/TimePicker/TimePicker.js
 @ ./node_modules/@mui/x-date-pickers/TimePicker/index.js
 @ ./node_modules/material-react-table/dist/index.esm.js
 @ ./lib/webparts/testTablaMui/components/App.js
 @ ./lib/webparts/testTablaMui/components/TestTablaMui.js
 @ ./lib/webparts/testTablaMui/TestTablaMuiWebPart.js

./node_modules/@mui/x-date-pickers/MobileDatePicker/MobileDatePicker.js 46:89
Module parse failed: Unexpected token (46:89)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     }, defaultizedProps.slots),
|     slotProps: _extends({}, defaultizedProps.slotProps, {
>       field: ownerState => _extends({}, resolveComponentProps(defaultizedProps.slotProps?.field, ownerState), extractValidationProps(defaultizedProps), {   
|         ref
|       }),
 @ ./node_modules/@mui/x-date-pickers/MobileDatePicker/index.js 1:0-54 1:0-54
 @ ./node_modules/@mui/x-date-pickers/DatePicker/DatePicker.js
 @ ./node_modules/@mui/x-date-pickers/DatePicker/index.js
 @ ./node_modules/material-react-table/dist/index.esm.js
 @ ./lib/webparts/testTablaMui/components/App.js
 @ ./lib/webparts/testTablaMui/components/TestTablaMui.js
 @ ./lib/webparts/testTablaMui/TestTablaMuiWebPart.js

./node_modules/@mui/x-date-pickers/DesktopDateTimePicker/DesktopDateTimePicker.js 48:71
Module parse failed: Unexpected token (48:71)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|   const isTimeViewActive = isInternalTimeView(popperView);
|   return /*#__PURE__*/_jsxs(React.Fragment, {
>     children: [inViewRenderers[!isTimeViewActive ? popperView : 'day']?.(_extends({}, rendererProps, {
|       view: !isTimeViewActive ? popperView : 'day',
|       focusedView: focusedView && isDatePickerView(focusedView) ? focusedView : null,
 @ ./node_modules/@mui/x-date-pickers/DesktopDateTimePicker/index.js 1:0-64 1:0-64
 @ ./node_modules/@mui/x-date-pickers/DateTimePicker/DateTimePicker.js
 @ ./node_modules/@mui/x-date-pickers/DateTimePicker/index.js
 @ ./node_modules/material-react-table/dist/index.esm.js
 @ ./lib/webparts/testTablaMui/components/App.js
 @ ./lib/webparts/testTablaMui/components/TestTablaMui.js
 @ ./lib/webparts/testTablaMui/TestTablaMuiWebPart.js

This is my package.json:

{
  "name": "test-tabla-mui-spfx",
  "version": "0.0.1",
  "private": true,
  "engines": {
    "node": ">=16.13.0 <17.0.0 || >=18.17.1 <19.0.0"
  },
  "main": "lib/index.js",
  "scripts": {
    "build": "gulp bundle",
    "clean": "gulp clean",
    "test": "gulp test"
  },
  "dependencies": {
    "@emotion/react": "^11.13.0",
    "@emotion/styled": "^11.13.0",
    "@fluentui/react": "^8.106.4",
    "@microsoft/sp-component-base": "1.18.2",
    "@microsoft/sp-core-library": "1.18.2",
    "@microsoft/sp-lodash-subset": "1.18.2",
    "@microsoft/sp-office-ui-fabric-core": "1.18.2",
    "@microsoft/sp-property-pane": "1.18.2",
    "@microsoft/sp-webpart-base": "1.18.2",
    "@mui/icons-material": "^5.16.6",
    "@mui/material": "^5.16.6",
    "@mui/x-date-pickers": "^7.12.0",
    "material-react-table": "^2.13.1",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "tslib": "2.3.1"
  },
  "devDependencies": {
    "@microsoft/rush-stack-compiler-4.7": "0.1.0",
    "@rushstack/eslint-config": "2.5.1",
    "@microsoft/eslint-plugin-spfx": "1.18.2",
    "@microsoft/eslint-config-spfx": "1.18.2",
    "@microsoft/sp-build-web": "1.18.2",
    "@types/webpack-env": "~1.15.2",
    "ajv": "^6.12.5",
    "eslint": "8.7.0",
    "gulp": "4.0.2",
    "typescript": "4.7.4",
    "@types/react": "17.0.45",
    "@types/react-dom": "17.0.17",
    "eslint-plugin-react-hooks": "4.3.0",
    "@microsoft/sp-module-interfaces": "1.18.2"
  }
}

How can I solve this error? How can I use Material React Table with SPFx?

Thanks in advance!

Upvotes: 0

Views: 98

Answers (1)

Shaxzod
Shaxzod

Reputation: 1

The errors you're encountering in your SPFx project with Material React Table are related to the usage of optional chaining (?.) and nullish coalescing (??) operators in your dependencies. These modern JavaScript features are not supported out-of-the-box by the default SPFx TypeScript configuration.

Upvotes: 0

Related Questions