oxc-project/oxc · error · OxcDiagnostic

<script setup>` cannot contain ES module exports.

Error message

<script setup>` cannot contain ES module exports.

What it means

The vue/no-export-in-script-setup rule disallows ES module export statements inside a `<script setup>` block. `<script setup>` is compiled by the Vue SFC compiler into the body of the component's `setup()` function, so `export` / `export default` syntax has no valid target there and breaks compilation of the component. Everything declared in `<script setup>` is already implicitly exposed to the template.

Source

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

use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

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

fn no_export_in_script_setup_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("<script setup>` cannot contain ES module exports.").with_label(span)
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow `export` in `<script setup>`
    ///
    /// ### Why is this bad?
    ///
    /// The previous version of `<script setup>` RFC used `export` to define variables used in templates,
    /// but the new `<script setup>` RFC has been updated to define without using `export`.
    /// See [Vue RFCs - 0040-script-setup](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0040-script-setup.md) for more details.
    ///
    /// ### Examples
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove the `export` keyword — top-level bindings in `<script setup>` are already usable in the template.
  2. Move the exported helper/constant into a separate .js/.ts module and import it inside `<script setup>`.
  3. If you need a normal `<script>` block alongside (e.g. for named exports or run-once logic), split the file into both `<script>` and `<script setup>` blocks.
  4. Re-run oxlint to verify the diagnostic cleared.

Example fix

// before
<script setup>
export const MAX = 10; // cannot contain ES module exports
const count = ref(0);
</script>

// after
<script setup>
import { MAX } from './constants';
const count = ref(0);
</script>
Defensive patterns

Strategy: validation

Validate before calling

# catch exports in <script setup> before the SFC compiler does
npx oxlint src/

Prevention

When it happens

Trigger: Writing any `export`, `export default`, or re-export statement inside a `<script setup>` block in a .vue file that oxlint scans, e.g. `export const foo = 1` inside `<script setup>`. Migrating a plain module into `<script setup>` and leaving its exports behind.

Common situations: Converting a normal `<script>` block to `<script setup>` without stripping exports; trying to share helpers from a component file by exporting them; copy-pasting composable code that ends with `export` into the block.

Related errors


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