oxc-project/oxc · warning · OxcDiagnostic

' ' is a compiler macro and doesn't need to be imported.

Error message

'{name}' is a compiler macro and doesn't need to be imported.

What it means

The vue/no-import-compiler-macros rule reports imports of Vue compiler macros (`defineProps`, `defineEmits`, `defineExpose`, `withDefaults`, etc.) inside `<script setup>`. These macros are global, auto-provided by the SFC compiler, and are compiled away — importing them is unnecessary noise and can even bind the wrong binding. The message "'{name}' is a compiler macro and doesn't need to be imported." comes from no_import_compiler_macros_diagnostic.

Solutions

  1. Delete the macro names from the import statement (or delete the whole import if it only contained macros).
  2. Configure your editor's auto-import to ignore `defineProps`/`defineEmits`/`defineExpose`/`withDefaults`.
  3. Optionally apply the suggested fix: the diagnostic's help text is 'Remove the import statement for this macro.'
  4. Re-run oxlint to verify.

Example fix

// before
<script setup>
import { defineProps, ref } from 'vue';
const props = defineProps<{ id: string }>();
</script>

// after
<script setup>
import { ref } from 'vue';
const props = defineProps<{ id: string }>();
</script>
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Inside a `<script setup>` block, an import declaration whose specifier names a compiler macro, e.g. `import { defineProps, defineEmits } from 'vue'`. The rule walks ImportDeclarationSpecifier / ModuleExportName nodes to find the imported macro names.

Common situations: IDE auto-import adding `defineProps` to the import list; migrating from a setup() function where macros were genuinely imported; copy-pasting snippets that self-contain their imports; older codebases that predate the macro-globals behavior.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/22532f77226d5624. Report an issue: GitHub.

Appendix: source

Thrown at crates/oxc_linter/src/rules/vue/no_import_compiler_macros.rs:12

use oxc_ast::{
    AstKind,
    ast::{ImportDeclarationSpecifier, ModuleExportName},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

use crate::{AstNode, context::LintContext, frameworks::FrameworkOptions, rule::Rule};

fn no_import_compiler_macros_diagnostic(span: Span, name: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("'{name}' is a compiler macro and doesn't need to be imported."))
        .with_help("Remove the import statement for this macro.")
        .with_label(span)
}

fn invalid_import_compiler_macros_diagnostic(span: Span, name: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!(
        "'{name}' is a compiler macro and can't be imported outside of `<script setup>`."
    ))
    .with_help("Remove the import statement for this macro.")
    .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct NoImportCompilerMacros;

declare_oxc_lint!(
    /// ### What it does
    ///

View on GitHub (pinned to e1e7af627c)