slidevjs/slidev · error · Error

Module not found: ${specifier}.\nAvailable modules: ${Object

Error message

Module not found: ${specifier}.\nAvailable modules: ${Object.keys(deps).join(', ')}. Please refer to https://sli.dev/custom/config-code-runners#additional-runner-dependencies

What it means

Thrown inside the sandboxed JS/TS runner when user code calls __slidev_import('x') for a specifier that is not in the monacoRunDeps allow-list. Only modules explicitly registered as runner dependencies can be imported in the browser sandbox.

Source

Thrown at packages/client/setup/code-runners.ts:86

  const onError = (error: any) => result.value.push({ error: String(error) })
  const logger = (...objs: any[]) => result.value.push(objs.map(printObject))
  const vmConsole = Object.assign({}, console)
  vmConsole.info = vmConsole.log = vmConsole.debug = vmConsole.warn = vmConsole.error = logger
  vmConsole.clear = () => result.value.length = 0
  try {
    const wrappedCode = `return async (console, __slidev_import, __slidev_on_error) => {
    ${configs.monacoRunUseStrict ? `"use strict";` : ''}
      try {
        ${fixupCode(code)}
      } catch (e) {
        __slidev_on_error(e)
      }
    }`
    // eslint-disable-next-line no-new-func
    ;(new Function(wrappedCode)())(vmConsole, (specifier: string) => {
      const mod = deps[specifier]
      if (!mod)
        throw new Error(`Module not found: ${specifier}.\nAvailable modules: ${Object.keys(deps).join(', ')}. Please refer to https://sli.dev/custom/config-code-runners#additional-runner-dependencies`)
      return mod
    }, onError)
  }
  catch (error) {
    onError(error)
  }

  function printObject(arg: any): CodeRunnerOutputText {
    if (typeof arg === 'string') {
      return {
        text: arg,
      }
    }
    return {
      text: objectToText(arg),
      highlightLang: 'javascript',
    }
  }

View on GitHub (pinned to 0d798ace58)

Solutions

  1. Register the dependency in your code-runners config so it appears in #slidev/monaco-run-deps
  2. Inline the needed logic in the snippet instead of importing
  3. Bundle the dependency into a custom client module and register it under its specifier

Example fix

// before
import _ from 'lodash'
// after - register in setup
import { defineApp } from '@slidev/types'
// declare deps so the runner can resolve 'lodash'
Defensive patterns

Strategy: validation

Validate before calling

const allowedSpecifiers = new Set(Object.keys(monacoRunDeps))
codeImports(specifier).forEach(s => {
  if (!allowedSpecifiers.has(s)) throw new Error(`Unregistered import: ${s}`)
})

Type guard

function isRegisteredDep(spec: string, deps: Record<string, unknown>): spec is string {
  return spec in deps
}

Prevention

When it happens

Trigger: Writing `import _ from 'lodash'` (or any specifier) in a runnable code block without registering lodash in monaco-run-deps.

Common situations: Assuming npm packages are auto-bundled into the client; locally-working imports that aren't shipped to the slide deck.

Related errors


AI-assisted analysis of slidevjs/slidev@0d798ace58 (2026-08-12). Data as JSON: /api/errors/f883e1ceb7e4c9a2. Report an issue: GitHub.