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
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
detective
✓ import detective from 'detective-vue2';
✗ import { detective } from 'detective-vue2';
The library exports a default function for dependency detection. Use a default import in ESM contexts.
detective
✓ const detective = require('detective-vue2');
This is the CommonJS import style, commonly used in Node.js environments.
Demonstrates how to use `detective-vue2` to extract module dependencies from a Vue Single File Component's content, covering script, template, and style imports.
const fs = require('fs');
const detective = require('detective-vue2');
// Example Vue SFC content with various dependencies
const vueFileContent = `
<template>
<div>
<MyComponent :prop="variableFromScript"></MyComponent>
<router-link to="/foo">Go to Foo</router-link>
</div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import MyComponent from './components/MyComponent.vue';
import { someUtility } from '@/utils/helpers';
const variableFromScript = ref('hello');
console.log(someUtility());
</script>
<style lang="scss">
@import './styles/base.scss';
.container {
color: #333;
}
</style>
`;
try {
const dependencies = detective(vueFileContent);
console.log('Detected dependencies:', dependencies);
// Expected output will include: 'vue', './components/MyComponent.vue', '@/utils/helpers', './styles/base.scss'
} catch (error) {
console.error('Error detecting dependencies:', error);
}
// To run:
// 1. Create a project: `mkdir my-app && cd my-app && npm init -y`
// 2. Install dependencies: `npm install detective-vue2 typescript`
// 3. Save this code as `quickstart.js`
// 4. Execute: `node quickstart.js`
Debug
Known issues
breakingVersion 2.0.0 introduced significant internal changes and potentially breaking API modifications from the 1.x series. Users upgrading from v1 should review their integration carefully.fixConsult the `detective-vue2` GitHub repository and any related `detective-typescript` changelogs for specific migration instructions, as detailed breaking changes were not explicitly listed in the v2.0.0 release notes beyond 'Full Changelog'.
affects: >=2.0.0
gotchaThe `typescript` package is a required peer dependency, meaning it must be explicitly installed alongside `detective-vue2` for the library to function correctly when processing TypeScript code.fixEnsure `typescript` is installed in your project: `npm install typescript`.
affects: >=1.0.0
gotchadetective-vue2 requires Node.js version 18 or higher. Running it on older Node.js versions will result in execution errors.fixUpgrade your Node.js environment to version 18 or newer.
affects: <18.0.0 (Node.js)
breakingVersion 2.2.0 updated the underlying `detective-typescript` dependency to v14.0.0. This major update in a core parsing dependency may introduce new behaviors or breaking changes related to TypeScript parsing, which could indirectly affect `detective-vue2`'s output.fixReview dependency detection results carefully after upgrading to v2.2.0+ if your project relies on specific TypeScript parsing nuances. Consult `detective-typescript` v14.0.0 changelog for details.
affects: >=2.2.0
gotchaEarly versions (prior to v2.0.2) of `detective-vue2` did not fully support Vue 3's `<script setup>` syntax. Initial support was added in v2.0.2, with further refinements for mixed `<script>` and `<script setup>` in v2.0.3.fixEnsure you are using `detective-vue2` version 2.0.3 or newer to correctly parse Vue SFCs utilizing `<script setup>`.
affects: <2.0.2
Errors
Common errors & fixes
Error: Cannot find module 'typescript' from '...' at Function.Module._resolveFilename
The 'typescript' package is a peer dependency and must be installed explicitly in your project.
fixRun `npm install typescript` or `yarn add typescript` in your project directory.
ReferenceError: require is not defined in ES module scope
You are attempting to use CommonJS `require()` syntax within an ES Module (ESM) file or context where it is not supported.
fixChange your import statement from `const detective = require('detective-vue2');` to `import detective from 'detective-vue2';`. SyntaxError: The requested module 'detective-vue2' does not provide an export named 'detective'
The `detective-vue2` package exports a default function, but you are trying to import it as a named export.
fixUse a default import: `import detective from 'detective-vue2';` instead of `import { detective } from 'detective-vue2';`. Error: Your current Node.js version is <18. detective-vue2 requires Node.js 18 or higher.
Your Node.js environment does not meet the minimum version requirement for `detective-vue2`.
fixUpgrade your Node.js installation to version 18 or newer (e.g., using `nvm install 18` and `nvm use 18`).
Audit
Dependencies
typescriptrequiredRequired as a peer dependency for parsing TypeScript code within Vue script blocks.