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

Error: Missing "./dist/esm/DateTimePicker.js" specifier in "react-datetime-picker" package #430

Open
jbarradas opened this issue Dec 18, 2024 · 1 comment
Labels
question Further information is requested

Comments

@jbarradas
Copy link

jbarradas commented Dec 18, 2024

We are having a hard time with these imports. As mostly falls back to CJS.

To force ESM we tried a few imports:

import DateTimePicker, { DateTimePickerProps } from 'react-datetime-picker'; <-- returns CJS
import DateTimePicker, { DateTimePickerProps } from 'react-datetime-picker/dist/esm';
import DateTimePicker, { DateTimePickerProps } from 'react-datetime-picker/dist/esm/DateTimePicker';
import DateTimePicker, { DateTimePickerProps } from 'react-datetime-picker/dist/esm/DateTimePicker.js';
import DateTimePicker, { DateTimePickerProps } from 'react-datetime-picker/dist/esm/index.js';

Right now, vitest can't handle it, and it's returning the following error:
Error: Missing "./dist/esm/DateTimePicker.js" specifier in "react-datetime-picker" package

Also, looking at your package.json exports, I see the following:

    ".": {
      "import": "./dist/esm/index.js",
      "require": "./dist/cjs/index.js"
    },
    "./dist/DateTimeInput": {
      "import": "./dist/esm/DateTimeInput.js",
      "require": "./dist/cjs/DateTimeInput.js"
    },
    "./dist/DateTimeInput.js": {
      "import": "./dist/esm/DateTimeInput.js",
      "require": "./dist/cjs/DateTimeInput.js"
    },
    "./dist/cjs/DateTimeInput": "./dist/cjs/DateTimeInput.js",
    "./dist/cjs/DateTimeInput.js": "./dist/cjs/DateTimeInput.js",
    "./dist/esm/DateTimeInput": "./dist/esm/DateTimeInput.js",
    "./dist/esm/DateTimeInput.js": "./dist/esm/DateTimeInput.js",
    "./dist/DateTimePicker.css": "./dist/DateTimePicker.css"
  }

This makes me wonder if you shouldn't being explicitly exporting the DateTimePicker instead of DateTimeInput?
Especially because the latter is a dependency of the former.

Would appreciate any help folks! :)

@wojtekmaj
Copy link
Owner

wojtekmaj commented Dec 19, 2024

Hmmm, according to arethetypeswrong it looks correct:

https://arethetypeswrong.github.io/?p=react-datetime-picker%406.0.1

I also can't understand why would 'react-datetime-picker' resolve to CJS, if import comes before require.

As for the explicit import of DateTimeInput, it's there to support @wojtekmaj/react-datetimerange-picker which uses components of this package internally :) You're not supposed to use these, it's not documented anywhere. I mean you can, it's not that open source police will come to your door, but I see no reason to. :D

@wojtekmaj wojtekmaj added the question Further information is requested label Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants