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

Attempted import error: Cannot find module 'date-fns-tz/format' or its corresponding type declarations #294

Open
Bielousov opened this issue Aug 8, 2024 · 1 comment

Comments

@Bielousov
Copy link

Bielousov commented Aug 8, 2024

Potentially related issue: #291

    "date-fns": "3.6.0",
    "date-fns-tz": "3.1.3",

Node: 18.20 (also tried 20.16)
TypeScript: 5.4.4
tsconfig:

  "compilerOptions": {
    "strict": true,
    "skipLibCheck": true,
    "moduleResolution": "node"
  },
  "exclude": ["node_modules"]

Upgrading from v1.3.7

When attempting to import any exported submodule directly, e.g:

import { format } from 'date-fns-tz/format';

TS cannot resolve the path, even though it is listed in the date-fns-tz/package.json:

Cannot find module 'date-fns-tz/format' or its corresponding type declarations.
There are types at './node_modules/date-fns-tz/dist/esm/format/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.ts(2307)

Changing this to import { format } from 'date-fns-tz'; works, but it increases the bundle size significantly.

Consider exporting type declarations: https://stackoverflow.com/a/77566206 along with ems and commonjs modules.

@Bielousov
Copy link
Author

Bielousov commented Aug 8, 2024

It appears that changing "moduleResolution" to nodenext, node16 or bundler fixes the import issue, although this isn't an option for me unfortunately. Also this wasn't the case in date-fns-tz@v1.3.7, nor it is mentioned in documentation anywhere, nor used in the library own tsconfig.

@Bielousov Bielousov changed the title Attempted import error: Cannot find module 'date-fns-tz/format' or its corresponding type declarations Missing types condition to the package.json#exports: Cannot find module 'date-fns-tz/format' or its corresponding type declarations Aug 8, 2024
@Bielousov Bielousov changed the title Missing types condition to the package.json#exports: Cannot find module 'date-fns-tz/format' or its corresponding type declarations Attempted import error: Cannot find module 'date-fns-tz/format' or its corresponding type declarations Aug 8, 2024
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

1 participant