The package includes TypeScript declarations. They import types from React and
React Router, so the package declares these peer dependencies:
@types/react>=17 <20
@types/react-router-dom^5.1.7
npm 7 and later installs peer dependencies for you. If npm install reports a
peer dependency conflict, use an @types/react version in that range. The
API reference lists the
exported types.
The stylesheet ships in the npm package. Configure your bundler to handle CSS
imports.
Import only these two paths: the package root and
@getstoryteller/storyteller-sdk-javascript/dist/storyteller.min.css. Version
11 no longer ships index.js, types/*.d.ts, or SDK source files, so other
paths fail.
A default import (import Storyteller from '@getstoryteller/storyteller-sdk-javascript')
works only in ES module builds. In CommonJS builds, including Jest, use
import * as Storyteller.
The npm package includes the Story player, Clips player, Poll, Quiz, and caption
code in its single JavaScript file. Your bundler decides how that code loads.
The script-tag build downloads the same code on demand instead.
Your bundler needs a CSS loader for the stylesheet require. Node.js can
require or import the JavaScript entry, for example during server
rendering, but views work only in the browser. Load the stylesheet only through
your browser build.
The Storyteller Web Showcase keeps its
PackagedStoryteller import
and stylesheet import in one browser-only module.
Call initialize and wait for it to resolve before you create a Storyteller
view. Replace demo-api-key with your API key. Top-level await works only in
ES modules. Otherwise, call initialize inside an async function, as shown in
Handle initialization errors.
{"slug": "getting-started-npm", "page_title": "Install from npm", "page_url": "getting-started/npm/", "canonical_url": "/web/getting-started/npm/", "markdown": "# Install from npm\n\nUse the npm package when a bundler, such as webpack or Vite, builds your\napplication's JavaScript. The package is\n[`@getstoryteller/storyteller-sdk-javascript`](https://www.npmjs.com/package/@getstoryteller/storyteller-sdk-javascript).\n\n## Install the package\n\n```shell\nnpm install @getstoryteller/storyteller-sdk-javascript\n```\n\n### TypeScript declarations {#typescript-declarations}\n\nThe package includes TypeScript declarations. They import types from React and\nReact Router, so the package declares these peer dependencies:\n\n- `@types/react` `>=17 <20`\n- `@types/react-router-dom` `^5.1.7`\n\nnpm 7 and later installs peer dependencies for you. If `npm install` reports a\npeer dependency conflict, use an `@types/react` version in that range. The\n[API reference](../reference/index.md#typescript-declarations) lists the\nexported types.\n\n## Import the SDK and styles\n\nImport both files from code that runs in the browser.\n\n```javascript\nimport * as Storyteller from '@getstoryteller/storyteller-sdk-javascript';\nimport '@getstoryteller/storyteller-sdk-javascript/dist/storyteller.min.css';\n```\n\nThe stylesheet ships in the npm package. Configure your bundler to handle CSS\nimports.\n\nImport only these two paths: the package root and\n`@getstoryteller/storyteller-sdk-javascript/dist/storyteller.min.css`. Version\n11 no longer ships `index.js`, `types/*.d.ts`, or SDK source files, so other\npaths fail.\n\nA default import (`import Storyteller from '@getstoryteller/storyteller-sdk-javascript'`)\nworks only in ES module builds. In CommonJS builds, including Jest, use\n`import * as Storyteller`.\n\nThe npm package includes the Story player, Clips player, Poll, Quiz, and caption\ncode in its single JavaScript file. Your bundler decides how that code loads.\nThe script-tag build downloads the same code on demand instead.\n\n### CommonJS browser bundles\n\nThe package also supports `require` in browser code built with CommonJS:\n\n```javascript\nconst Storyteller = require('@getstoryteller/storyteller-sdk-javascript');\nrequire('@getstoryteller/storyteller-sdk-javascript/dist/storyteller.min.css');\n```\n\nYour bundler needs a CSS loader for the stylesheet `require`. Node.js can\n`require` or `import` the JavaScript entry, for example during server\nrendering, but views work only in the browser. Load the stylesheet only through\nyour browser build.\n\nThe Storyteller Web Showcase keeps its\n[`PackagedStoryteller` import](https://github.com/getstoryteller/storyteller-showcase-web/blob/11.0.0/nextjs/src/components/contexts/loadPackagedStoryteller.ts#L1)\nand stylesheet import in one browser-only module.\n\n## Initialize the SDK\n\n```javascript\nawait Storyteller.sharedInstance.initialize('demo-api-key');\n```\n\nCall `initialize` and wait for it to resolve before you create a Storyteller\nview. Replace `demo-api-key` with your API key. Top-level `await` works only in\nES modules. Otherwise, call `initialize` inside an `async` function, as shown in\n[Handle initialization errors](../Quickstart.md#handle-initialization-errors).\n\n## Add a Story row\n\n```html\n<div id=\"storyteller-stories-row\" style=\"height: 200px\"><\/div>\n```\n\n```javascript\nconst storyRow = new Storyteller.StorytellerStoriesRowView(\n 'storyteller-stories-row'\n);\n```\n\nCall `storyRow.destroy()` before your application removes or replaces the\ncontainer.\n\n## Next steps\n\n- [Show your first Story row](../Quickstart.md)\n- [Use React or Next.js](react-nextjs.md)\n- [Configure views](../StorytellerListView.md)\n", "copy_markdown_include_header": false, "base_path": "", "ai_dir": "ai", "missing_payload_behavior": "empty"}