Flow: Namespace '"date-fns"' has no exported member 'Locale'

See original GitHub issue

I compiled the following code…

src/index.ts)

import {format as dateFormat} from 'date-fns-tz';

dateFormat(new Date(), 'YYYYMMdd', {timeZone: 'America/New_York'});

The following error occurred.

./node_modules/.bin/tsc --project tsconfigs.json
node_modules/date-fns-tz/typings.d.ts:34:31 - error TS2694: Namespace '"date-fns"' has no exported member 'Locale'.

34   locale?: import('date-fns').Locale
                                 ~~~~~~


Found 1 error.

Environments

package-lock.json)

{
  "name": "reproduce-date-fns-tz-typing-bug",
  "version": "1.0.0",
  "lockfileVersion": 1,
  "requires": true,
  "dependencies": {
    "date-fns": {
      "version": "2.0.0-alpha.13",
      "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-2.0.0-alpha.13.tgz",
      "integrity": "sha1-oP1yPEZ7XFupi8nX/hvu9eak1ZY="
    },
    "date-fns-tz": {
      "version": "1.0.6",
      "resolved": "https://registry.npmjs.org/date-fns-tz/-/date-fns-tz-1.0.6.tgz",
      "integrity": "sha512-g0IY9CebRuyB5e2GIueO9mHpySpauMxSkbdkmVQEWi/R3w49ikYxC3dBNruGSOegwiNLI9cjuM0POZOFX0r8zQ=="
    },
    "typescript": {
      "version": "3.3.3",
      "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.3.3.tgz",
      "integrity": "sha512-Y21Xqe54TBVp+VDSNbuDYdGw0BpoR/Q6wo/+35M8PAU0vipahnyduJWirxxdxjsAkS7hue53x2zp8gz7F05u0A=="
    }
  }
}

tsconfigs.json)

{
  "compilerOptions": {
    "lib": [
      "es2018"
    ],
    "module": "commonjs",
    "newLine": "LF",
    "target": "es5",
    "strict": true
  },
  "include": [
    "./src"
  ]
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
maniatorcommented, Oct 11, 2019

Thank you @maniator for the proposed fix. I have changed this in 1.0.8-beta.1. Please confirm whether this fixes the issue with Flow and I’ll publish a proper release.

@saiichihashimoto I am not a maintainer of date-fns. If you would like additional types exposed please file an issue on the date-fns project.

Hmmm We no longer have that original issue, but now it just says

Cannot resolve module date-fns-tz.

when we run flow @marnusw

1reaction
chasingmaxwellcommented, Jul 3, 2019

date-fns-tz imports the type Locale from date-fns here: https://github.com/marnusw/date-fns-tz/blob/master/src/index.js.flow#L4

As far as I can tell looking at date-fns that type is not exported. So, when I run flow in a project depending on date-fns-tz, I get the following error:

Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/date-fns-tz/index.js.flow:4:15

Cannot import Locale because there is no Locale export in date-fns.

     1│ // @flow
     2│ // This file is generated automatically by `scripts/build/typings.js`. Please, don't change it.
     3│
     4│ import type { Locale } from 'date-fns'
     5│
     6│ type OptionsWithTZ = {
     7│   weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6,

That error is coming from within date-fns-tz when flow evaluates its types.

I thought it was perhaps an issue with the version of date-fns but that appears not to be the case because even the earliest version allowed by the peerDependency range does not have Locale as an exported type.

Hopefully that helps. I tried my hand at updating with a PR myself, but when I found that Locale was not exported at all from date-fns, I figured it would probably take some higher level decision-making about where that type should be defined. Perhaps a pull request against date-fns to export that type might be in order.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Namespace 'Intl' has no exported member 'LocalesArgument'
Using React and TypeScript I'm trying to type a function that passes arguments to Date.toLocaleString but when I try to use Intl.LocalesArgument ...
Read more >
date-fns - modern JavaScript date utility library
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
Read more >
“Namespace '"fs"' has no exported member ... - Code Grepper
Queries related to “Namespace '"fs"' has no exported member 'MakeDirectoryOption”. Module '"react"' has no exported member 'Node'.
Read more >
ERROR: Namespace 'dayjs' has no exported member ... - Reddit
I've looked into it and the generated some-random-component.d.ts looks like the following for the locale object. locale = { ... daysOfWeek: ...
Read more >
How to Add react-i18next to Your React app | by Emily Xiong
React-i18next is internationalization framework for React. This blog is a step-by-step guide about adding react-118next to a React project, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found