Skip to content

Commit f41fe51

Browse files
Resolve bad import of @mui/x-date-pickers to date-fns internal file
1 parent 38512e2 commit f41fe51

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

vite.config.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { CommonServerOptions, defineConfig } from 'vite';
1111
import eslint from 'vite-plugin-eslint';
1212
import svgr from 'vite-plugin-svgr';
1313
import tsconfigPaths from 'vite-tsconfig-paths';
14+
import path from 'node:path';
1415

1516
const serverSettings: CommonServerOptions = {
1617
port: 3002,
@@ -43,4 +44,18 @@ export default defineConfig((config) => ({
4344
build: {
4445
outDir: 'build',
4546
},
47+
resolve: {
48+
alias: {
49+
/* "@mui/x-date-pickers/AdapterDateFns/AdapterDateFns" do an import from 'date-fns/_lib/format/longFormatters'
50+
* which cause rollup error '[commonjs--resolver] Missing "./_lib/format/longFormatters" specifier in "date-fns" package'.
51+
* - we fix the no default import with a shim that will fix that
52+
* - we do a second alias to resolve the import to a non-exported file to date-fns/_lib/...
53+
*/
54+
'date-fns/_lib/format/longFormatters': path.resolve(import.meta.dirname, 'vite.shim.x-date-pickers.js'),
55+
'virtual:date-fns/_lib/format/longFormatters': path.resolve(
56+
import.meta.dirname,
57+
'node_modules/date-fns/_lib/format/longFormatters'
58+
),
59+
},
60+
},
4661
}));

vite.shim.x-date-pickers.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* Copyright © 2025, RTE (http://www.rte-france.com)
3+
* This Source Code Form is subject to the terms of the Mozilla Public
4+
* License, v. 2.0. If a copy of the MPL was not distributed with this
5+
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6+
*/
7+
8+
import { longFormatters } from 'virtual:date-fns/_lib/format/longFormatters';
9+
export default longFormatters; // patch bad import of @mui/x-date-pickers/AdapterDateFns/AdapterDateFns.js
10+
export * from 'virtual:date-fns/_lib/format/longFormatters';

0 commit comments

Comments
 (0)