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

Cannot import in 3.0.1: A declaration file cannot be imported without 'import type' #3620

Closed
perrin4869 opened this issue Dec 20, 2023 · 7 comments

Comments

@perrin4869
Copy link

I can't find other reports here yet, but I ran into #3588 like everyone else, but unfortunately the fix introduced a new error in my case:

../../node_modules/date-fns/index.d.mts(1,15): error TS2846: A declaration file cannot be imported without 'import type'. Did you mean to import an implementation file './index.js' instead?

I am guessing this might be the reason that import type was there originally in 3.0.0. Not quite sure what the fix is though, it's quite surprising...
I can try to put together a reproduction later

@perrin4869 perrin4869 changed the title Cannot import in 3.0.1 Cannot import in 3.0.1: A declaration file cannot be imported without 'import type' Dec 20, 2023
@kossnocorp
Copy link
Member

Hey! I expected that, but I couldn't reproduce it. I'd appreciate it if you could produce a minimal repro example.

@kossnocorp
Copy link
Member

@perrin4869 please try date-fns@3.0.2-rc.1. I still need repro to add to smoke tests, but I hope it finally fixes the problem.

@perrin4869
Copy link
Author

beautiful, that seems to have done the trick!!! thanks!!
I'll put together a repro soon 😃

@nstuyvesant
Copy link

nstuyvesant commented Dec 20, 2023

image

I ran into this as well.

@kossnocorp - I see the solution in 3.0.2-rc.1 is to copy the contents of the .d.ts files to the .d.mts files.

Why not just modify the exports in the package.json and do away with all the .d.mts files? TypeScript won't care about the extension as long as the exports are setup correctly. You could simplify the exports as well...

Each export like this one...

    "./addMinutes": {
      "require": {
        "types": "./addMinutes.d.ts",
        "default": "./addMinutes.js"
      },
      "import": {
        "types": "./addMinutes.d.mts",
        "default": "./addMinutes.mjs"
      }
    },

could be reduced to...

    "./addMinutes": {
      "types": "./addMinutes.d.ts",
      "require":  "./addMinutes.js"
      "import":  "./addMinutes.mjs"
    },

@kossnocorp
Copy link
Member

@nstuyvesant I think you're right, and it's possible to point to the same d.ts. I tried many combinations to make "Are types wrong" happy, and this one seems to have slipped away.

Regarding reducing, it's possible as it will give another error.

@kossnocorp
Copy link
Member

Shipped the fix with date-fns@3.0.2

@kossnocorp
Copy link
Member

Unfortunately, I messed up attw results, and pointing to the same d.ts indeed gives the error: https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md

So I rolled back to the original solution by copying the content and released it as date-fns@3.0.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants