use client directive must be placed before other expressions
hect1c opened this issue · 2 comments
hect1c commented
Using latest next 13.4.1-canary.0
and latest swc-plugin-coverage-instrument 0.0.18
and when running next dev
get the following error
The "use client" directive must be placed before other expressions. Move it to the top of the file to resolve this issue.
,-[/nextjs-app-repro/node_modules/.pnpm/next@13.4.1-canary.0_@babel+core@7.20.7_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/client/script.js:1:1]
1 | "use client";
: ^^^^^^^^^^^^^
2 | "use strict";
3 | Object.defineProperty(exports, "__esModule", {
4 | value: true
`----
The error was caused by importing 'next/dist/client/next-dev.js' in 'undefined'.
Here is a minimal repro https://github.com/hect1c/nextjs-app-repro install dependencies and run dev. When I remove the swc plugin it runs fine but when I add it then the issue appears.
Oddly enough this happens in another project using same latest version but I don't use the App directory and am using pages and thus not utilizing any of the RSC features.
kwonoj commented
Plugin may able to do this by their own, but in my opinion this should be handled in upstream swc itself.