Registry / devops / rollup-plugin-import-trace

rollup-plugin-import-trace

JSON →
library1.0.1jsnpmunverified

Rollup/Vite plugin that attaches a detailed import trace chain to build errors, helping developers quickly identify which import path led to a problematic file. Version 1.0.1 is the current stable release. It works with Rollup 3/4 and Vite 5/6/7. Unlike Rollup's built-in `watchFiles` (which lists all watched files), this plugin records only the specific chain of imports causing the error. Ships TypeScript types and supports both ESM and CommonJS environments. Minimal configuration required: just add `importTrace()` first in the plugins array.

npm install rollup-plugin-import-trace
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-IMPO
R
rollup-plugin-import-trace
devopsjavascriptv1.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

importTrace
import { importTrace } from 'rollup-plugin-import-trace'
const importTrace = require('rollup-plugin-import-trace').importTrace
Library is ESM-first but also exports a CJS default; named import works in both systems. Ensure your bundler resolves correctly.
default
import importTrace from 'rollup-plugin-import-trace'
const importTrace = require('rollup-plugin-import-trace')
Default export is an alias for the named export. In CJS, use `{ importTrace }` or `require('rollup-plugin-import-trace').default`.
patchErrorWithTrace
import { patchErrorWithTrace } from 'rollup-plugin-import-trace'
const patchErrorWithTrace = require('rollup-plugin-import-trace').patchErrorWithTrace
Utility function to format and append import trace to error messages. Accepts `unknown` type, no-op if trace missing.

Demonstrates basic usage of importTrace plugin with Rollup, catching an error and inspecting the importTrace property.

import { importTrace } from 'rollup-plugin-import-trace'; import { rollup } from 'rollup'; const bundle = await rollup({ input: 'src/index.js', plugins: [importTrace()] }); try { await bundle.generate({ format: 'es' }); } catch (error) { console.log(error.importTrace); // outputs import chain or undefined }
Debug
Known issues
gotchaPlugin must be listed first in the plugins array to capture import relationships.
fix
Place `importTrace()` before any other plugins in the Rollup or Vite configuration.
affects: >=1.0.0
gotchaIn Vite dev mode, error formatting is automatic; in other contexts you must manually call `patchErrorWithTrace()`.
fix
Use `patchErrorWithTrace(error)` before logging the error message for CLI tools or custom error handling.
affects: >=1.0.0
gotchaImport trace may not be present for all error types; relies on Rollup's error structure and may miss runtime errors.
fix
Check `error.importTrace` existence before using it, or rely on `patchErrorWithTrace()` which handles absence gracefully.
affects: >=1.0.0
Errors
Common errors & fixes
Error: 'importTrace' is not exported from 'rollup-plugin-import-trace'
Using CommonJS `require` with named export incorrectly
fix
Use `const { importTrace } = require('rollup-plugin-import-trace')` or switch to ESM import.
TypeError: Cannot read properties of undefined (reading 'id')
Plugin was not added to the plugins array, or was added after other plugins that override `resolveId` hook.
fix
Ensure `importTrace()` is the first plugin in the plugins array.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources