noConvexWrongRuntimeImports (JavaScript)
Language JavaScript (and super languages)
Summary
Section titled “Summary”- Diagnostic Category:
lint/nursery/noConvexWrongRuntimeImports - This rule doesn’t have a fix.
- The default severity of this rule is warning.
- This rule belongs to the following domains:
- Sources:
- Inspired from
@convex-dev/import-wrong-runtime
- Inspired from
How to configure
Section titled “How to configure”{ "linter": { "rules": { "nursery": { "noConvexWrongRuntimeImports": "error" } } }}Description
Section titled “Description”Disallow importing Node.js runtime files from Convex runtime files.
Files in your convex folder that start with "use node" run in Node.js. All other
files run in the Convex runtime, which doesn’t support Node.js APIs. If a Convex runtime
file imports a "use node" file, that code runs in the Convex runtime too, and can fail.
Move the shared code into a file without "use node", or add "use node" to the
importing file if it only defines actions.
Type-only imports are allowed. Files that Convex doesn’t deploy as functions, such as
schema.ts, test files, and files in _generated, are not checked.
Examples
Section titled “Examples”Invalid
Section titled “Invalid”"use node";
export function formatAmount(amount: number) { return `$${amount.toFixed(2)}`;}import { formatAmount } from "./stripe";/convex/payments.ts:1:30 lint/nursery/noConvexWrongRuntimeImports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This file runs in the Convex runtime, but it imports ./stripe, which runs in Node.js.
> 1 │ import { formatAmount } from "./stripe";
│ ^^^^^^^^^^
2 │
ℹ Files with the "use node" directive run in Node.js. When you import one from a file without the directive, its code runs in the Convex runtime instead, where Node.js APIs aren't available.
ℹ Move the code you need into a file without the "use node" directive, or add the directive to this file if it only defines actions.
ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.
export function formatAmount(amount: number) { return `$${amount.toFixed(2)}`;}import { formatAmount } from "./format";Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.