microsoft / microsoft/fluentui

API extractor prevents usage of re-exports 💥

Open
#20,694 25 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Area: Build System Fluent UI react-components (v9) Resolution: Soft Close Status: Blocked
Dominant language
TypeScript
Stars
20.3k
Forks
2.9k
Avg merge
2d 9h
Merged PRs (30d)
46

Description

In I am trying to re-export functions in #20628:

// 🚨 breaks build
export * as shorthands from './shorthands/index';

But it's impossible, see #18906. I modified code to use import/export as suggested:

// 🚨 still breaks build
import * as shorthands from "./shorthands/index";
export { shorthands };

Error is similar to #19360, but it seems that problem is different as it breaks on @fluentuiu/react-make-styles that contains re-export:

ERR! [10:48:59 AM] ■ Extracting Public API surface from 'packages\react-make-styles\lib\index.d.ts'
ERR! Analysis will use the bundled TypeScript version 4.1.5
ERR! [10:48:59 AM] x Error detected while running '_wrapFunction'
ERR! [10:48:59 AM] x ------------------------------------
ERR! [10:49:00 AM] x Error: Internal Error: The ""packages/make-styles/lib/shorthands/index"" symbol has a ts.SyntaxKind.SourceFile declaration which is not (yet?) supported by API Extractor
ERR!
ERR! You have encountered a software defect. Please consider reporting the issue to the maintainers of this
application.

Only code below passes build:

import { margin, padding } from "./shorthands/index";

export const shorthands = { margin, padding };

But it breaks tree shaking for bundlers as shorthands is an object now and any usage of shorthands.* will include all functions to bundle *.

  • * if Terser is not used, but it will be used in any setup

Rollup REPL.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the API Extractor failure from packages/react-make-styles/lib/index.d.ts, focusing on the re-export through packages/make-styles/lib/shorthands/index and the @fluentuiu/react-make-styles build. Compare the failing namespace re-exports with the working explicit-export example and the related issues #18906 and #19360. Done means the intended re-export passes API Extractor without requiring an object workaround that harms tree shaking.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.