Skip to content

vite cjsInterop SyntaxError with MUI #9605

Open
@cjoecker

Description

@cjoecker

Reproduction

  1. Clone this repository
  2. Run npm install
  3. Run npm run build
  4. Run npm run start

See the error on the console

System Info

Node 22.2.0, Mac OS.
It is also failing on earlier node versions

Used Package Manager

npm

Expected Behavior

CJS libraries work with vite and cjsInterop.

Actual Behavior

On build start commands, Remix is throwing the error

export { AdapterDateFns } from './AdapterDateFnsV3';
^^^^^^

SyntaxError: Unexpected token 'export'
    at wrapSafe (node:internal/modules/cjs/loader:1350:18)
    at Module._compile (node:internal/modules/cjs/loader:1379:20)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1518:10)
    at Module.load (node:internal/modules/cjs/loader:1249:32)
    at Function.Module._load (node:internal/modules/cjs/loader:1065:12)
    at cjsLoader (node:internal/modules/esm/translators:318:15)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:258:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:262:25)
    at ModuleLoader.import (node:internal/modules/esm/loader:475:24)
    at run (/Users/christian/Documents/remix-bug-report/node_modules/@remix-run/serve/dist/cli.js:112:15)

Interestingly, it is working fine with npm run dev

I already tried ssr.noExternal on the vite config.

I also tried importing the package as

import pkg from "@mui/x-date-pickers/AdapterDateFnsV3/index";
const { AdapterDateFns } = pkg;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions