date-fns: Upgrade leads to 'Cannot augment module 'xxxx' with value exports because it resolves to a non-module entity

If I run tsc --noEmit --incremental false I get a long list of Cannot augment... error messages. Everything was fine with 2.10.0 but fails now with 2.11.0

...
node_modules/date-fns/typings.d.ts:15311:9 - error TS2649: Cannot augment module 'ro' with value exports because it resolves to a non-module entity.

15311   const ro: Locale
              ~~

node_modules/date-fns/typings.d.ts:15314:9 - error TS2649: Cannot augment module 'ru' with value exports because it resolves to a non-module entity.

15314   const ru: Locale
              ~~

node_modules/date-fns/typings.d.ts:15317:9 - error TS2649: Cannot augment module 'sk' with value exports because it resolves to a non-module entity.
...

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 15
  • Comments: 18 (2 by maintainers)

Most upvoted comments

Still struggling with this lib.

One thing that helps is:

yarn why date-fns

If yarn show multiple versions of date-fns you are f… Make sure you have the same version of date-fns for all!!! you packages

@dkozickis Can you please reopen this issue. As you can see the problem still exists. I tried it with 2.15.0 + 2.16.1 always the same problem. Only downgrading to 2.11.1. helps

I use date-fns in several modules. In some 2.16.1 works in others it fails. Works with 2.16.1

import { differenceInSeconds, fromUnixTime } from 'date-fns'
import { formatISO9075 } from 'date-fns'

Works only with 2.11.1

import { formatISO, parseISO, toDate } from 'date-fns';
import { isSameDay, sub } from 'date-fns'

In both modules I remove unnecessary locales with

        // Weitere Infos: https://date-fns.org/docs/webpack
        new webpack.ContextReplacementPlugin(
            /date\-fns[\/\\]/,
            new RegExp(`[/\\\\\](${supportedLocales.join('|')})[/\\\\\]`)
        ),

I momentarily added this inside tsconfig.json "skipLibCheck": true,

  • date-fns version: ^2.16.1
  • Angular version: 11.2.1
  • typescript version: ~4.1.5

I have this issue in version 2.15.0 . I am using this in Angular v9

import { format } from 'date-fns';

image

I have this issue in version 2.15.0 . I am using this in Angular v9

import { format } from 'date-fns';

image

I still have, too.so how can you solve it?

Same problem here

  • System: Ubuntu 20.04
  • Node version: 12.16.3
  • Project: Angular v10

Downgrade to 2.11.1 didn’t work

P.S.: When using same version of date-fns in an ionic+stencil project, it seems to work fine. Maybe some issue with Angular?

I have this with date-fns 2.20.2, using typescript 4.2.3. In my project, the root of the repository has a package.json and contains frontend code, but the /server folder has its own package.json and contains cloud functions. Both packages use date-fns and have their own copies installed.

I’m getting around this by adding this to my CI, which is somewhat suboptimal

mv server/node_modules/date-fns/typings.d.ts bak
npm run build --prefix server
mv bak server/node_modules/date-fns/typings.d.ts

I still have this issue with imports from date-fns/fp. Switching to non-fp fixes it.