Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails because "use client" is placed after "use strict" #152

Open
LucasStbnr opened this issue Oct 3, 2024 · 0 comments
Open

Build fails because "use client" is placed after "use strict" #152

LucasStbnr opened this issue Oct 3, 2024 · 0 comments

Comments

@LucasStbnr
Copy link

When I am using swc-plugin-coverage-instrument to calculate my coverage on my Next.js project,the build fails because /next-runtime-env/build/provider/env-provider.js and /next-runtime-env/build/provider/use-env-context.js have "use client" placed after "use strict".

Example :

// env-provider.js

"use strict";
'use client';
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnvProvider = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const env_context_1 = require("./env-context");
/**
 * Provides the environment variables to the application.
 *
 * Usage:
 * ```ts
 * <EnvProvider env={{ NODE_ENV: 'test', API_URL: 'http://localhost:3000' }}>
 *   <App />
 * </EnvProvider>
 * ```
 */
const EnvProvider = ({ children, env }) => {
    return (0, jsx_runtime_1.jsx)(env_context_1.EnvContext.Provider, { value: env, children: children });
};
exports.EnvProvider = EnvProvider;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW52LXByb3ZpZGVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3Byb3ZpZGVyL2Vudi1wcm92aWRlci50c3giXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFlBQVksQ0FBQzs7OztBQUtiLCtDQUEyQztBQU0zQzs7Ozs7Ozs7O0dBU0c7QUFDSSxNQUFNLFdBQVcsR0FBeUIsQ0FBQyxFQUFFLFFBQVEsRUFBRSxHQUFHLEVBQUUsRUFBRSxFQUFFO0lBQ3JFLE9BQU8sdUJBQUMsd0JBQVUsQ0FBQyxRQUFRLElBQUMsS0FBSyxFQUFFLEdBQUcsWUFBRyxRQUFRLEdBQXVCLENBQUM7QUFDM0UsQ0FBQyxDQUFDO0FBRlcsUUFBQSxXQUFXLGVBRXRCIn0=

The error :

Failed to compile.

./node_modules/next-runtime-env/build/provider/env-provider.js
Error: 
  × The "use client" directive must be placed before other expressions. Move it to the top of the file to resolve this issue.
   ╭─[/Users/lustoebn/Projects/nextweb/node_modules/next-runtime-env/build/provider/env-provider.js:1:1]
 1 │ "use strict";
 2 │ 'use client';
   · ─────────────
 3 │ Object.defineProperty(exports, "__esModule", { value: true });
 4 │ exports.EnvProvider = void 0;
 5 │ const jsx_runtime_1 = require("react/jsx-runtime");
   ╰────

When I manually invert the directives in the node_modules, it works as expected.

My Next.js config :

const nextConfig = {
    ...
    experimental: {
        swcPlugins: [['swc-plugin-coverage-instrument', { coverageVariable: '__coverage__' }]],
        workerThreads: false,
        cpus: 1,
    },
    ...
};

Versions used :
"swc-plugin-coverage-instrument": "0.0.24"
"next-runtime-env": "3.2.2"

@LucasStbnr LucasStbnr changed the title Build fail because "use client" placed after "use strict" Build fails because "use client" is placed after "use strict" Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant