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

getPackageExportSizes fails on packages with conditional export maps #61

Open
arshaw opened this issue Dec 7, 2022 · 1 comment
Open

Comments

@arshaw
Copy link

arshaw commented Dec 7, 2022

While investigating why Exports Analysis fails for fullcalendar on bundlephobia, I wrote this script:

import { getPackageExportSizes } from 'package-build-stats'

const sizes = await getPackageExportSizes('@fullcalendar/core@6.0.0-beta.3')
console.log(sizes)

I get the following error:

Error: Package path . is not exported from package /tmp/tmp-build/packages/build-@fullcalendarcore-fIi/node_modules/@fullcalendar/core (see exports field in /tmp/tmp-build/packages/build-@fullcalendarcore-fIi/node_modules/@fullcalendar/core/package.json)
    at /Users/adam/Scratch/bundlephobia-test/node_modules/enhanced-resolve/lib/ExportsFieldPlugin.js:104:7
    at Hook.eval [as callAsync] (eval at create (/Users/adam/Scratch/bundlephobia-test/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:22:1)
    at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/adam/Scratch/bundlephobia-test/node_modules/tapable/lib/Hook.js:18:14)
    at Resolver.doResolve (/Users/adam/Scratch/bundlephobia-test/node_modules/enhanced-resolve/lib/Resolver.js:432:16)
    at /Users/adam/Scratch/bundlephobia-test/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:74:17
    at /Users/adam/Scratch/bundlephobia-test/node_modules/enhanced-resolve/lib/DescriptionFileUtils.js:118:13
    at /Users/adam/Scratch/bundlephobia-test/node_modules/enhanced-resolve/lib/forEachBail.js:16:12
    at onJson (/Users/adam/Scratch/bundlephobia-test/node_modules/enhanced-resolve/lib/DescriptionFileUtils.js:108:6)
    at Array.<anonymous> (/Users/adam/Scratch/bundlephobia-test/node_modules/enhanced-resolve/lib/DescriptionFileUtils.js:68:7)
    at runCallbacks (/Users/adam/Scratch/bundlephobia-test/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:27:15)

It seems like a conditional exports map inpackage.json like this is not supported. Here's what fullcalendar has:

  "exports": {
    "./package.json": "./package.json",
    "./index.cjs": "./index.cjs",
    "./index.js": "./index.js",
    ".": {
      "types": "./index.d.ts",
      "require": "./index.cjs",
      "import": "./index.js"
    },
@Ivordir
Copy link

Ivordir commented Apr 4, 2023

This seems to be the issue: webpack/enhanced-resolve#313
Adding a "default" export in the package.json should fix the issue.

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

2 participants