These docs cover qiankun 3.0 (RC) — install it with npm i qiankun@rc. For 2.x, see the v2 docs.
Skip to content

Error codes and solutions ​

Every QiankunError thrown by qiankun has a stable code property and a solution link at the end of its message.

中文

Identify framework errors ​

ts
import { loadMicroApp, QiankunError } from 'qiankun';

const microApp = loadMicroApp({ name, entry, container });

void microApp.mountPromise.catch((error: unknown) => {
  if (error instanceof QiankunError) {
    console.error(error.code, error.message);
  } else {
    console.error(error);
  }
});

Framework errors thrown by the loader, sandbox, and shared modules are all instances of the same QiankunError class. Micro-app code, the browser, and single-spa may also throw other error types, which callers still need to handle.

Public contract ​

ts
import { type QiankunErrorCode } from 'qiankun';

declare class QiankunError extends Error {
  readonly code: QiankunErrorCode;
}

The public contract is limited to two things: identifying framework errors with instanceof QiankunError, and the read-only code property. Only qiankun creates QiankunError instances; the constructor is not public API. The message ends with a solution link. Links point to Chinese pages, each with an English counterpart.

Code conventions ​

Codes use lowercase words separated by hyphens and describe the cause and remedy. The same cause shares a code across packages. Moving files, rewording a message, or adding other errors does not change existing codes. Branch on error.code instead of comparing complete messages.

Code index ​

Released under the MIT License.