{"record":{"id":"345d4346836e25ce","repo":"parcel-bundler/parcel","slug":"use-server-entry-must-be-imported-in-a-server-envi","errorCode":null,"errorMessage":"use server-entry must be imported in a server environment","messagePattern":"use server-entry must be imported in a server environment","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/transformers/js/src/JSTransformer.js","lineNumber":801,"sourceCode":"    } else if (\n      !asset.env.isServer() &&\n      !asset.env.isLibrary &&\n      directives.includes('use server')\n    ) {\n      asset.setEnvironment({\n        context: 'react-server',\n        sourceType: 'module',\n        outputFormat: 'commonjs',\n        engines: asset.env.engines,\n        includeNodeModules: true,\n        isLibrary: false,\n        sourceMap: asset.env.sourceMap,\n        shouldOptimize: asset.env.shouldOptimize,\n        shouldScopeHoist: asset.env.shouldScopeHoist,\n      });\n    } else if (directives.includes('use server-entry')) {\n      if (!asset.env.isServer()) {\n        throw new Error(\n          'use server-entry must be imported in a server environment',\n        );\n      }\n      asset.bundleBehavior = 'isolated';\n    }\n\n    // Server actions must always be wrapped so they can be parcelRequired.\n    if (directives.includes('use server')) {\n      asset.meta.shouldWrap = true;\n    }\n\n    for (let dep of dependencies) {\n      if (dep.kind === 'WebWorker') {\n        // Use native ES module output if the worker was created with `type: 'module'` and all targets\n        // support native module workers. Only do this if parent asset output format is also esmodule so that\n        // assets can be shared between workers and the main thread in the global output format.\n        let outputFormat;\n        if (","sourceCodeStart":783,"sourceCodeEnd":819,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/transformers/js/src/JSTransformer.js#L783-L819","documentation":"Thrown when a JS asset contains the React Server Components directive `'use server-entry'` but the asset's environment is not a server environment (asset.env.isServer() === false). The directive marks a module as the client entry bootstrap from a server bundle; running it in a browser/service-worker/worklet target is invalid. The transformer enforces this before setting bundleBehavior = 'isolated'.","triggerScenarios":"A module whose top-level directive list includes 'use server-entry' is resolved into a bundle whose env.context is not server (browser, web-worker, service-worker, worklet). Typical when the same file is imported from both server and client code without an env boundary, or a target mislabels the context.","commonSituations":"Sharing a single 'use server-entry' file between client and server entry points; a misplaced directive in a file imported by a browser bundle; an env override (e.g. in a URL/dep) that switched context away from 'react-server'/'node'.","solutions":["Move the 'use server-entry' directive into a file that is only reachable from the server entry.","If the same code path is needed on the client, split it: keep 'use server-entry' on the server module and import a separate client-safe module from the browser bundle.","Audit `addURLDependency`/`addDependency` calls and target env overrides that may have flipped context.","Check your targets in package.json: the entry that uses 'use server-entry' must have a server context."],"exampleFix":"// before: src/entry.js used by both server and client\n'use server-entry';\nimport {App} from './App';\n\n// after: split into two files\n// src/entry.server.js\n'use server-entry';\nimport {App} from './App';\n// src/entry.client.js (no directive)\nimport {App} from './App';","handlingStrategy":"validation","validationCode":"// Ensure 'use server-entry' files are only reachable from server entries\nconst path = require('path');\nfunction assertServerOnly(filePath, serverEntryDirs) {\n  const rel = path.relative(process.cwd(), filePath);\n  if (!serverEntryDirs.some(d => rel.startsWith(d))) {\n    throw new Error(`file ${filePath} uses 'use server-entry' but is outside server entry dirs ${serverEntryDirs}`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep server entry files in a dedicated directory (e.g. src/server/) and never import them from browser code.","Use Parcel's environment conditions to branch imports rather than sharing the directive-tagged file."],"tags":["rsc","directives","env-context","react-server"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}