Comments (6)
It's a bug of SWC relay plugin
from next.js.
Could you try one thing, move the use server
directive, to the beginning of the function. Say, here:
export async function setValue(string: string): Promise<void> {
'use server';
// comment out the next two statements to successfully compile
Why? Well, it has been a while now, but IIRC, relay, pre-processes the file, and adds more code to it, that might be pushing down the use server
directive at the top:
// for example after relay processes the file we might have
import someRelayStuff from './folder-made-by-the-relay-compiler';
// more of those
'use server';
import { revalidatePath } from "next/cache";
And that causes the issue you are seeing. We can try to confirm this by placing the use server
directive within the function, which is also an allowed pattern.
from next.js.
moving the directive inside the function results in this error:
jgeschwendt@repro-next-relay-server-action % pnpm build
> [email protected] build /Users/jgeschwendt/GitHub/jgeschwendt/repro-next-relay-server-action
> next build
▲ Next.js 14.2.3
Creating an optimized production build ...
Failed to compile.
./src/app/actions.ts
Error:
x It is not allowed to define inline "use server" annotated Server Actions in Client Components.
| To use Server Actions in a Client Component, you can either export them from a separate file with "use server" at the top, or pass them down through props from a Server Component.
|
| Read more: https://nextjs.org/docs/app/api-reference/functions/server-actions#with-client-components
|
,-[/Users/jgeschwendt/GitHub/jgeschwendt/repro-next-relay-server-action/src/app/actions.ts:3:1]
3 | import type { actionsSetValueMutation } from '@/relay/actionsSetValueMutation.graphql';
4 |
5 | export async function setValue(string: string): Promise<void> {
6 | "use server";
: ^^^^^^^^^^^^
7 |
8 | // comment out the next two statements to successfully compile
9 | const taggedNode = graphql`
`----
Import trace for requested module:
./src/app/actions.ts
./src/app/Interactive.tsx
> Build failed because of webpack errors
from next.js.
Not on my laptop now, but are you importing this function directly into a client module (use client)? If so, import it to a server component instead and pass it down as props, just to test if all of this makes it work... We are exploring the issue.
from next.js.
my bad, yes moving it into the RSC works
https://github.com/jgeschwendt/repro-next-relay-server-action/blob/rsc-action/src/app/page.tsx
from next.js.
Alright, but then maybe this is something that Relay should fix, as in, respect, or check for, the presence of use server
on the file. I'd say maybe open an issue over there, referencing this one.
from next.js.
Related Issues (20)
- Inconsistent parsing of data URLs in CSS in Next 14 HOT 1
- intercepting routes not rendering under nested route HOT 3
- Can't use Knex in instrumentation hook HOT 3
- Tab title is reset for a moment when navigating to a dynamic page HOT 1
- Dev mode fail s with(WasmHash._updateWithBuffer ) HOT 1
- Parallel Routes cause redundant RSC fetches on navigation HOT 5
- When using `<Script>` with `crossorigin` specified, `crossorigin` is missing from `<link>` that preloads the script
- Layout doesn't cache and gets 1 server re-render for each broken image link
- Fill property for Next Image doesn't seem to work. HOT 6
- 404 when redirecting in server action with subdomain rewrite rule
- Build Error when trying to compile with 'use client' files.
- NextResponse.redirect is not working in middleware HOT 1
- Layout rerenders on same segment route change HOT 4
- Docs: Replace "twitter.com" to "x.com"
- Add option to enable Turbopack with `create-next-app` HOT 6
- Redirect URL not updating correctly in browser after successful redirect HOT 10
- NextUrl pathname return wrong HOT 1
- "edge" runtime is not allowed in pages router getServerSideProps. "experimental-edge" is forced though it shouldn't be. HOT 1
- Triggering notFound in generateMetadata results in Error: NEXT_NOT_FOUND when the delayed notFound call is used (e.g. fetch) HOT 1
- Next.js Compatibility Issues on Chrome 80: Style, useEffect, and Query Problems HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.