Repository navigation
Does arkType support CommonJS, and is there a way to use it in NestJS? #1582
|
which framework better for validate data with arkType? |
Replies: 1 comment
|
ArkType is ESM-only, no CommonJS build exists. Checking the published package directly confirms it: For NestJS specifically, that matters because Nest's default compiler output is CommonJS. You have two realistic options:
For a NestJS project already on CJS, dynamic |
ArkType is ESM-only, no CommonJS build exists. Checking the published package directly confirms it:
package.jsonhas"type": "module", and theexportsmap only has adefaultcondition (pointing at the ESM output) plus a customark-tscondition for direct TS resolution, there's norequirecondition anywhere in it. Sorequire('arktype')will fail regardless of how you configure your project.For NestJS specifically, that matters because Nest's default compiler output is CommonJS. You have two realistic options:
import()inside your CJS Nest code to pull in ArkType at the call site. This works today with zero config changes and is the standard workaround for consuming an ESM-o…