{"id":22079,"library":"rollup-plugin-import-trace","title":"rollup-plugin-import-trace","description":"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.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/privatenumber/rollup-plugin-import-trace","tags":["javascript","rollup","rollup-plugin","vite","vite-plugin","import","trace","debug","error","typescript"],"install":[{"cmd":"npm install rollup-plugin-import-trace","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-import-trace","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-import-trace","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Library is ESM-first but also exports a CJS default; named import works in both systems. Ensure your bundler resolves correctly.","wrong":"const importTrace = require('rollup-plugin-import-trace').importTrace","symbol":"importTrace","correct":"import { importTrace } from 'rollup-plugin-import-trace'"},{"note":"Default export is an alias for the named export. In CJS, use `{ importTrace }` or `require('rollup-plugin-import-trace').default`.","wrong":"const importTrace = require('rollup-plugin-import-trace')","symbol":"default","correct":"import importTrace from 'rollup-plugin-import-trace'"},{"note":"Utility function to format and append import trace to error messages. Accepts `unknown` type, no-op if trace missing.","wrong":"const patchErrorWithTrace = require('rollup-plugin-import-trace').patchErrorWithTrace","symbol":"patchErrorWithTrace","correct":"import { patchErrorWithTrace } from 'rollup-plugin-import-trace'"}],"quickstart":{"code":"import { importTrace } from 'rollup-plugin-import-trace';\nimport { rollup } from 'rollup';\n\nconst bundle = await rollup({\n  input: 'src/index.js',\n  plugins: [importTrace()]\n});\n\ntry {\n  await bundle.generate({ format: 'es' });\n} catch (error) {\n  console.log(error.importTrace); // outputs import chain or undefined\n}","lang":"typescript","description":"Demonstrates basic usage of importTrace plugin with Rollup, catching an error and inspecting the importTrace property."},"warnings":[{"fix":"Place `importTrace()` before any other plugins in the Rollup or Vite configuration.","message":"Plugin must be listed first in the plugins array to capture import relationships.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use `patchErrorWithTrace(error)` before logging the error message for CLI tools or custom error handling.","message":"In Vite dev mode, error formatting is automatic; in other contexts you must manually call `patchErrorWithTrace()`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Check `error.importTrace` existence before using it, or rely on `patchErrorWithTrace()` which handles absence gracefully.","message":"Import trace may not be present for all error types; relies on Rollup's error structure and may miss runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use `const { importTrace } = require('rollup-plugin-import-trace')` or switch to ESM import.","cause":"Using CommonJS `require` with named export incorrectly","error":"Error: 'importTrace' is not exported from 'rollup-plugin-import-trace'"},{"fix":"Ensure `importTrace()` is the first plugin in the plugins array.","cause":"Plugin was not added to the plugins array, or was added after other plugins that override `resolveId` hook.","error":"TypeError: Cannot read properties of undefined (reading 'id')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}