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

[email protected] failures in typescript and parcel builds and runtime #9676

Open
isakstarlander opened this issue Apr 30, 2024 · 6 comments

Comments

@isakstarlander
Copy link

🐛 bug report

After upgrading date-fns to version 3.6.0 the parcel build started failing, not finding the exported functions. Apart from that the runtime function calls in the dev server fails with provided errors documented in the reproduction repository.

This seems to be a problem for parcel builds in particular, a related issue in date-fns can be found here: date-fns/date-fns#3744

🤔 Expected Behavior

Build should be successful and runtime function calls should work as described in the date-fns repository.

😯 Current Behavior

Build fails unless specifying the alias function name. Runtime the format function throws an error.

Build error:

@parcel/core: node_modules/date-fns/index.mjs does not export 'format'

  /Users/isakstarlander/git/date-fns-parcel-reproduction/formatImport.ts:17:10
    16 | 
  > 17 | import { format } from "date-fns";
  >    |          ^^^^^^
    18 | 
    19 | function renderFormattedDate() {

Runtime error:

TypeError: Cannot read properties of undefined (reading 'y')
    at format.mjs:378:21
    at Array.map (<anonymous>)
    at format (format.mjs:367:6)
    at renderFormattedDate (formatImport.ts:10:26)
    at ghM9m.date-fns (formatImport.ts:21:1)
    at newRequire (index.0dd3d9d0.js:71:24)
    at index.0dd3d9d0.js:122:5
    at index.0dd3d9d0.js:145:3

🔦 Context

This issue prevents us from upgrading date-fns to the latest supported major version.

💻 Code Sample

Reproduction repository: https://github.com/Milkywire/date-fns-parcel-reproduction

🌍 Your Environment

Software Version(s)
Parcel 2.12.0
date-fns 3.6.0
Node 18
Operating System MacOS
@Poky85
Copy link

Poky85 commented May 13, 2024

In the meantime this is workaround:

import format from 'date-fns/format';

@conan
Copy link

conan commented Nov 20, 2024

The workaround doesn't seem to work in v4.1.0, I can't find any way of using v4 of date-fns with parcel:

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

gives:

@parcel/core: node_modules/date-fns/format.js does not export 'format'

The workaround causes my typescript compilation to fail:

import format from "date-fns/format";
tsc --no-emit
error TS2613: Module '"node_modules/date-fns/format"' has no default export. Did you mean to use 'import { format } from "node_modules/date-fns/format"' instead?
Software Version(s)
Parcel 2.12.0
Node v20.14.0
npm 10.9.0
date-fns 4.1.0
OS Ubuntu 22.04.5 LTS

@github-actions github-actions bot removed the Stale Inactive issues label Nov 20, 2024
@ryanking1809
Copy link

I noticed this issue converting some javascript to typescript. And for some reason it doesn't seem to be a problem with javascript. Not ideal, but with that in mind, I've managed to work around it by importing and exporting format via a .js file.

format.js

import { format } from 'date-fns';
export { format };

@kai-dorschner-twinsity
Copy link

kai-dorschner-twinsity commented Nov 28, 2024

The question is, is it a problem with date-fns or with the parcel resolver? I can't wrap my head around it. The package.json of date-fns links many (possibly unnecessarily explicit and even more possibly broken) exports https://github.com/date-fns/date-fns/blob/6c70ac6d073ebe869e42795f5e71dfecf5abbea0/package.json#L21

Edit:
The imports work when you add the --no-scope-hoist parameter to the parcel bundle process.

@peguimasid
Copy link

Any updated on this? I think this issue is related to date-fns/date-fns#3670

@Saturn
Copy link

Saturn commented Feb 25, 2025

Ran into this issue too. The workaround e.g. importing formatters, longFormatters explicitly so they don't get (wrongly) left out of the bundle seems to be working in my case.

Presumably other bundlers don't have this issue with date-fns tree shaking 🤷‍♂️🤷‍♂️

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

No branches or pull requests

8 participants