Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath ‘./format/index.js’ is not defined by “exports” in …

The date-fns and date-fns-tz Node.js packages are being updated, and version 3 has some bugs. When you try to use them in TypeScript you get the error message

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './format/index.js' is not defined by "exports" in ...

Currently, the only solution is the restrict the version to 2.

In package.json add the lines

{
 "name": "MY_PROJECT_NAME",
  ...
  "overrides": {
    "date-fns": "^2.0.0"
  }
}

In the terminal run

npm install

Check the effect of the new settings in the terminal with

npm ls date-fns

The output should be something like

js-application@1.0.0 /Users/…
└─┬ date-fns-tz@2.0.0
└── date-fns@2.30.0 overridden

Leave a comment

Your email address will not be published. Required fields are marked *