Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pickers] AdapterDayjs Module not found #8849

Closed
rafshawn opened this issue May 3, 2023 · 21 comments
Closed

[pickers] AdapterDayjs Module not found #8849

rafshawn opened this issue May 3, 2023 · 21 comments
Labels
component: pickers This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information

Comments

@rafshawn
Copy link

rafshawn commented May 3, 2023

Duplicates

* [x]  I have searched the existing issues

Latest version

* [x]  I have tested the latest version

Current behavior 😯

Error on compile, AdapterDayjs module not found, causing breaking issues.

Context 🔦

Been having trouble with this module every time I compile. AdapterDayjs is not exported from the @mui/x-date-pickers module, even though its been imported. Tried searching up the issue and thought it might be an issue with dependency but I'm not entirely sure how to check whether I need to upgrade or downgrade anything. Tried uninstalling and reinstalling x-date-pickers

I get an import error:

Attempted import error: 'AdapterDayjs' is not exported from '@mui/x-date-pickers' (imported as 'AdapterDayjs').

Which then causes an issue in exporting the module:

export 'AdapterDayjs' (imported as 'AdapterDayjs') was not found in '@mui/x-date-pickers'Attempted import error: 'AdapterDayjs' is not exported from '@mui/x-date-pickers' (imported as 'AdapterDayjs').

For context, these are my dependencies:

"dependencies": {
    "@date-io/dayjs": "^2.16.0",
    "@emotion/react": "^11.10.8",
    "@emotion/styled": "^11.10.8",
    "@mui/icons-material": "^5.11.11",
    "@mui/lab": "^5.0.0-alpha.129",
    "@mui/material": "^5.12.3",
    "@mui/styles": "^5.5.0",
    "@mui/x-data-grid": "^6.3.0",
    "@mui/x-date-pickers": "^6.3.0",
    "dayjs": "^1.11.7",
    "material-table": "^2.0.3",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router-dom": "^6.3.0",
    "react-scripts": "5.0.0",
    "web-vitals": "^2.1.0"
},
@LukasTy
Copy link
Member

LukasTy commented May 3, 2023

Hello, have you tried importing directly from @mui/x-date-pickers/AdapterDayjs? I can't see any reference in docs suggesting a root import is possible. 🤔

Suggestion: Consider dropping @date-io/dayjs dependency as all the adapters are shipped internally starting v6.3.0 😉

@LukasTy LukasTy added status: waiting for author Issue with insufficient information component: pickers This is the name of the generic UI component, not the React module! labels May 3, 2023
@rafshawn
Copy link
Author

rafshawn commented May 6, 2023

Hello, have you tried importing directly from @mui/x-date-pickers/AdapterDayjs? I can't see any reference in docs suggesting a root import is possible. 🤔

Suggestion: Consider dropping @date-io/dayjs dependency as all the adapters are shipped internally starting v6.3.0 😉

Thank you for the suggestion! Tried doing that and I only installed the dayjs module based off a suggestion I found on the internet. I get the same error importing directly, I was thinking if it could be an issue with the project itself?

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label May 6, 2023
@LukasTy
Copy link
Member

LukasTy commented May 8, 2023

I get the same error importing directly, I was thinking if it could be an issue with the project itself?

Could you please provide a code snippet or a "codesandbox" demo with the code that is causing issues?
I'll remind you that root-level imports are not supported for the adapters.
import { AdapterDayjs } from '@mui/x-date-pickers'
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'

@LukasTy LukasTy added the status: waiting for author Issue with insufficient information label May 8, 2023
@github-actions
Copy link

Since the issue is missing key information and has been inactive for 7 days, it has been automatically closed. If you wish to see the issue reopened, please provide the missing information.

@IvanAlcuinoAxpara
Copy link

IvanAlcuinoAxpara commented Feb 13, 2024

From @LukasTy
I tried this in my remix.js 2.6
"react": "^18.2.0",
"@mui/material": "^5.15.4"
"@emotion/react": "^11.11.3"
"@mui/x-date-pickers": "^6.19.4"
Node 20.10.0

import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'
But still having an issue.

node:internal/process/esm_loader:40
internalBinding('errors').triggerUncaughtException(
^
Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'C:\projects\my-project\node_modules@mui\x-date-pickers\AdapterDayjs' is not supported resolving ES modules imported from C:\projects\my-project\build\index.js
Did you mean to import @mui/x-date-pickers/node/AdapterDayjs/index.js?

2nd Attempt:
file:///C:/projects/my-project/build/index.js:1296
import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs/index.js";
^^^^^^^^^^^^
SyntaxError: Named export 'AdapterDayjs' not found. The requested module '@mui/x-date-pickers/AdapterDayjs/index.js' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@mui/x-date-pickers/AdapterDayjs/index.js';
const { AdapterDayjs } = pkg;

at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
at async loadESM (node:internal/process/esm_loader:34:7)
at async handleMainPromise (node:internal/modules/run_main:113:12)

Node.js v20.10.0

Both tried Node 20 and 18 has still the same issue.

3rd Attempt:
import pkg from '@mui/x-date-pickers/AdapterDayjs/index.js';
const { AdapterDayjs } = pkg;

X [ERROR] No matching export in "node_modules/@mui/x-date-pickers/AdapterDayjs/index.js" for import "default"

app/routes/release.$id.tsx:35:7:
  35 │ import pkg from "@mui/x-date-pickers/AdapterDayjs/index.js"; 

Can anybody help?

@LukasTy
Copy link
Member

LukasTy commented Feb 13, 2024

I have the same issue. Can anybody help?

Could you please provide a reproduction example or at least the import you are using and the version of the package?

@LukasTy
Copy link
Member

LukasTy commented Feb 13, 2024

@IvanAlcuinoAxpara This looks like an environment setup issue.
However, there are known ESM support issues for @mui packages (mui/material-ui#37335, mui/material-ui#30671).

  1. Have you tried Node 18?
  2. Have you tried updating the import path as suggested? For example, update it to @mui/x-date-pickers/AdapterDayjs/index.js.

@IvanAlcuinoAxpara
Copy link

Yap I did both but still having the same issue. I updated my original post.

@LukasTy
Copy link
Member

LukasTy commented Feb 13, 2024

@IvanAlcuinoAxpara I've setup a fresh Remix project with the default recommended template, installed @mui/x-date-pickers, and did not see any issues in both dev and build.
Could you please provide more information on your setup?
Ideally we'd like to see a minimal repository or a StackBlitz or CodeSandbox demo. 😉

@shish-ko
Copy link

@IvanAlcuinoAxpara, @LukasTy, this is my problem (and possible solution for your problem). It can be solved by importing from node subfolder. I can hardly axplain why, but it works for me.

@LukasTy
Copy link
Member

LukasTy commented Feb 20, 2024

@shish-ko Could you please provide a reproduction example or repository for us to test? 🤔
I have tried running the Pickers package in a Vite project without problems, maybe in your case, there is some conflict with the setup. 🤔 🤷

@shish-ko
Copy link

shish-ko commented Feb 20, 2024

@LukasTy https://github.com/shish-ko/mui_vite
npm i -> npm run dev works
npm i -> npm run build -> npm run preview fails

@sriram-balaganeshan
Copy link

i couldn't import DayCalendarSkeleton if i import it will error shows export 'DayCalendarSkeleton' (imported as 'DayCalendarSkeleton') was not found in '@mui/x-date-pickers'

@dev-scripts
Copy link

dev-scripts commented Mar 25, 2024

// with date-fns v2.x
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFns';
// with date-fns v3.x
import { AdapterDateFns } from '@mui/x-date-pickers/AdapterDateFnsV3';
// with date-fns v2.x
import de from 'date-fns/locale/de';
// with date-fns v3.x
import { de } from 'date-fns/locale/de';

<LocalizationProvider dateAdapter={AdapterDateFns} adapterLocale= {de}> <DatePicker label="Controlled picker" /> </LocalizationProvider>

@shish-ko
Copy link

@LukasTy Hi! Is there any updates?

@LukasTy
Copy link
Member

LukasTy commented Mar 28, 2024

Hi! Is there any updates?

Sorry, I didn't have the chance to look at it yet.
It's been a very busy month with the preparations for the stable release. 🙈

@synle
Copy link

synle commented Mar 30, 2024

@LukasTy @rafshawn

I finally managed to get this working. Essentially, what I did was implement lazy loading for this particular component.

To elaborate, there's a component named DateTimeInput.tsx that utilizes these adapters. The initial import lines resemble the following:

import { AdapterMoment } from '@mui/x-date-pickers/AdapterMoment';
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker';
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';

export default function DateTimeInput(){
  return //... your code here
}

Subsequently, there's another component, Form.tsx, which utilizes the aforementioned component:

Instead of directly importing DateTimeInput which does not work, as shown below:

// this code does not work
import { DateTimeInput } from 'src/component/input/DateTimeInput';

function Form() {
  return <>
    <DateTimeInput />
  </>
}

I changed it to lazy loading and Suspense, resulting in successful execution. This code works for me.

// this will work
import { Suspense, lazy, useState } from 'react';

const DateTimeInput = lazy(() => import(`~/src/component/input/DateTimeInput`));

function Form() {
  return <Suspense>
    <DateTimeInput />
  </Suspense>
}

@maximemarc
Copy link

Hello if you use quickly delete the cache vite in the node module

@yukiyokotani
Copy link

I encountered the same issue when trying to use the Luxon Adapter.
I'm not sure why Rollup resolves the module on the CJS side, but since the Adapter itself exists as an ESM, I explicitly wrote the path resolution settings for the Adapter, and for now, it's working well.
Below is the vite.config.ts for that.

import { vitePlugin as remix } from '@remix-run/dev';
import { installGlobals } from '@remix-run/node';
import { defineConfig } from 'vite';
import tsconfigPaths from 'vite-tsconfig-paths';
import path from 'path';

installGlobals();

export default defineConfig({
  plugins: [
    remix({
      ssr: false,
    }),
    tsconfigPaths(),
  ],
  resolve: {
    alias: {
      '@mui/x-date-pickers/AdapterLuxon': path.resolve(
        __dirname,
        'node_modules/@mui/x-date-pickers/AdapterLuxon/AdapterLuxon.js',
      ),
    },
  },
  optimizeDeps: {
    include: [
      '@mui/material',
      '@mui/icons-material',
      '@emotion/react',
      '@emotion/styled',
    ],
    force: true,
  },
});

@Ishimwe-William
Copy link

Ishimwe-William commented May 2, 2024

install dayjs

npm install dayjs

@mahmoudmoravej
Copy link

For DayJs, I exacyly followed @yukiyokotani solution and it worked. Thanks!

export default defineConfig({
 //...
  resolve: {
    alias: {
      "@mui/x-date-pickers/AdapterDayjs": path.resolve(
        __dirname,
        "node_modules/@mui/x-date-pickers/AdapterDayjs/AdapterDayjs.js"
      ),
    },
  },
 //...
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pickers This is the name of the generic UI component, not the React module! status: waiting for author Issue with insufficient information
Projects
None yet
Development

No branches or pull requests