Skip to content

Conversation

@cornedor
Copy link
Contributor

@cornedor cornedor commented Aug 7, 2025

Directives like "use strict", "use client" or "use cache" should always be on top. Inserting an import statement on the first line breaks this.

For example with nextjs:

Ecmascript file had an error
> 1 | "use cache";
    | ^^^^^^^^^^^
  2 | import { cacheLife } from "next/dist/server/use-cache/cache-life";
  3 | import { cacheTag } from "next/dist/server/use-cache/cache-tag";
  4 | import { notFound } from "next/navigation";

The "use cache" directive must be at the top of the file.

This change will first scan if there is a line with "use ", and insert the import below it.

@changeset-bot
Copy link

changeset-bot bot commented Aug 7, 2025

🦋 Changeset detected

Latest commit: ce935de

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@swc-contrib/plugin-graphql-codegen-client-preset Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@CLAassistant
Copy link

CLAassistant commented Aug 7, 2025

CLA assistant check
All committers have signed the CLA.

@cornedor cornedor force-pushed the add-imports-below-directives branch from 5a98df4 to ce935de Compare August 7, 2025 10:29
@kdy1 kdy1 changed the title fix: Add import below directives fix(contrib/gql): Add import below directives Aug 7, 2025
@kdy1 kdy1 changed the title fix(contrib/gql): Add import below directives fix(contrib/graphql): Add import below directives Aug 7, 2025
@kdy1 kdy1 merged commit 5c67c0f into swc-project:main Aug 7, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants