canirequire

canirequire › CommonJS › @storybook/testing-library

Is @storybook/testing-library ESM-only? Can you require() it?

Instrumented version of Testing Library for Storybook Interactions

Last verified Sep 9, 2026 against @storybook/testing-library@0.2.2. Markdown · JSON

CommonJS CommonJS — require() works on every Node.js version we test

@storybook/testing-library ships CommonJS only. require("@storybook/testing-library") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "@storybook/testing-library" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

It also declares a "module" field, so bundlers such as webpack, Vite and esbuild pick up an ESM build for tree-shaking.

What to do

  1. require("@storybook/testing-library") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun.
  2. From ES modules use the default import: import testingLibrary from "@storybook/testing-library"; then destructure. Named imports only work when Node.js can statically detect the exports.
  3. TypeScript: types are bundled; install nothing extra.
  4. This package is deprecated: In Storybook 8, this package functionality has been integrated to a new package called @storybook/test, which uses Vitest APIs for an improved experience. When upgrading to Storybook 8 with 'npx storybook@latest upgrade', you will get prompted and will get an automigration for the new package. Please migrate when you can.
Latest
0.2.2 (Oct 2, 2023)
Module format
CommonJS
Last CommonJS version
0.2.2
TypeScript types
Bundled
Node engines
not declared
Weekly downloads
546K
License
MIT

Deprecated: In Storybook 8, this package functionality has been integrated to a new package called @storybook/test, which uses Vitest APIs for an improved experience. When upgrading to Storybook 8 with 'npx storybook@latest upgrade', you will get prompted and will get an automigration for the new package. Please migrate when you can.

Does @storybook/testing-library@0.2.2 actually load? Runtime test results

Installed and executed on Sep 9, 2026 with require("@storybook/testing-library") from a CommonJS file and import "@storybook/testing-library" from an ES module.

Runtimerequire("@storybook/testing-library")import "@storybook/testing-library"
Node.js 18✓ works✓ works
Node.js 20✓ works✓ works
Node.js 22✓ works✓ works
Node.js 24✓ works✓ works
Node.js 26✓ works✓ works
Bun 1.4.0✓ works✓ works

How to import @storybook/testing-library

ES modules (import)

import testingLibrary from "@storybook/testing-library";

Named imports from a CommonJS package only work when Node.js can statically detect them. If a named import fails, use the default import and destructure.

CommonJS (require)

const testingLibrary = require("@storybook/testing-library");

Module format by version

Derived from the type, main and exports fields of every stable release on npm, corrected where a runtime test of that version contradicted them (18 versions; the newest 18 shown).

VersionsFormatFirst published
0.0.0 – 0.2.2CommonJSOct 15, 2021

Frequently asked

Is @storybook/testing-library ESM-only?

@storybook/testing-library@0.2.2 is a CommonJS package. @storybook/testing-library ships CommonJS only. require("@storybook/testing-library") works on every Node.js version we test (18, 20, 22, 24 and 26) and in Bun. import "@storybook/testing-library" also works because Node.js and Bun can import CommonJS from ES modules, but only the default export is guaranteed; named imports depend on Node's static analysis of the module.

Can I import @storybook/testing-library with ES module syntax?

Yes. import testingLibrary from "@storybook/testing-library" works in Node.js and Bun because they support importing CommonJS modules. Named imports work only when Node.js can statically detect the exports.

Does @storybook/testing-library work in Bun?

Yes. import "@storybook/testing-library" loaded successfully in Bun 1.4.0 on Sep 9, 2026.

Does @storybook/testing-library ship TypeScript types?

Yes. @storybook/testing-library bundles its own type declarations; no @types package is needed.

Links

Other commonjs packages

Similar popularity