{"record":{"id":"1989232e17efa9f9","repo":"oxc-project/oxc","slug":"name-is-a-compiler-macro-and-can-t-be-imported","errorCode":null,"errorMessage":"'{name}' is a compiler macro and can't be imported outside of `<script setup>`.","messagePattern":"'(.+?)' is a compiler macro and can't be imported outside of `<script setup>`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/vue/no_import_compiler_macros.rs","lineNumber":18,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{ImportDeclarationSpecifier, ModuleExportName},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, context::LintContext, frameworks::FrameworkOptions, rule::Rule};\n\nfn no_import_compiler_macros_diagnostic(span: Span, name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"'{name}' is a compiler macro and doesn't need to be imported.\"))\n        .with_help(\"Remove the import statement for this macro.\")\n        .with_label(span)\n}\n\nfn invalid_import_compiler_macros_diagnostic(span: Span, name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"'{name}' is a compiler macro and can't be imported outside of `<script setup>`.\"\n    ))\n    .with_help(\"Remove the import statement for this macro.\")\n    .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoImportCompilerMacros;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow importing Vue compiler macros.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Compiler Macros like:\n    /// - `defineProps`","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vue/no_import_compiler_macros.rs#L1-L36","documentation":"The second diagnostic of vue/no-import-compiler-macros: \"'{name}' is a compiler macro and can't be imported outside of `<script setup>`.\" Compiler macros like `defineProps` only exist inside `<script setup>` blocks, where the SFC compiler transforms them. Importing them anywhere else (plain `<script>`, a .js module, a composable) produces code that calls a function which is not actually exported by 'vue' at that position, breaking the build at runtime or compile time.","triggerScenarios":"An import declaration resolving a compiler macro name in any context other than `<script setup>` — e.g. `import { defineProps } from 'vue'` in a plain .ts composable, in a `<script>` block without `setup`, or in a helper module that calls the macro.","commonSituations":"Extracting part of a component's prop logic into a helper file; mixing `<script>` and `<script setup>` and importing the macro in the wrong block; copy-pasting script-setup code into a plain module.","solutions":["Remove the macro import — the code cannot use compiler macros outside `<script setup>`.","Move the code that calls the macro (defineProps/defineEmits/...) back into the component's `<script setup>` block.","Replace macro usage with runtime equivalents in plain modules, e.g. `defineComponent({ props: {...} })` or `vue`'s runtime `defineComponent` API.","Re-run oxlint to confirm no remaining out-of-scope macro imports."],"exampleFix":"// before (composables/useThing.ts)\nimport { defineProps } from 'vue'; // can't be imported outside of `<script setup>`\nexport function useThing(props) { ... }\n\n// after (composables/useThing.ts)\nexport function useThing(props) { ... }\n// and in the component:\n<script setup>\nconst props = defineProps<{ id: string }>();\nuseThing(props);\n</script>","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep all compiler-macro usage inside `<script setup>` blocks only.","In plain modules use runtime APIs (defineComponent with props/emits options) instead of macros.","When extracting logic from a component into a helper, pass props/emits in as arguments rather than re-declaring macros."],"tags":["vue","script-setup","lint","compiler-macros","imports"],"backgroundTag":"macro-out-of-scope","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}