causaly / zod-validation-error

Wrap zod validation errors in user-friendly readable messages
MIT License
813 stars 11 forks source link

Version 3.0.1 causes import issues #253

Closed szethh closed 9 months ago

szethh commented 9 months ago

Running into import issues while building with vite 5. This only happens after updating to 3.0.1.

node:internal/event_target:1088
  process.nextTick(() => { throw err; });
                           ^
file:///C:/myapp/.svelte-kit/output/server/entries/endpoints/(authed)/submit/_server.ts.js:17
import { toValidationError } from "zod-validation-error";
         ^^^^^^^^^^^^^^^^^
SyntaxError: Named export 'toValidationError' not found. The requested module 'zod-validation-error' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from 'zod-validation-error';
const { toValidationError } = pkg;

    at ModuleJob._instantiate (node:internal/modules/esm/module_job:132:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:214:5)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async analyse (file:///C:/myapp/node_modules/.pnpm/@sveltejs+kit@2.4.0_@sveltejs+vite-plugin-svelte@3.0.1_svelte@4.2.9_vite@5.0.12/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:84:62)
    at async MessagePort.<anonymous> (file:///C:/myapp/node_modules/.pnpm/@sveltejs+kit@2.4.0_@sveltejs+vite-plugin-svelte@3.0.1_svelte@4.2.9_vite@5.0.12/node_modules/@sveltejs/kit/src/utils/fork.js:22:16)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:814:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)

Node.js v20.10.0

For now, I'm pinning the version to 3.0.0

PredokMiF commented 9 months ago

Named export 'fromZodError' not found.

Threebow commented 9 months ago

Can reproduce, although with a slightly different error. Pinning to 3.0.0 fixes it.

export { ValidationError } from './ValidationError';
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:77:18)
    at wrapSafe (node:internal/modules/cjs/loader:1288:20)
    at Module._compile (node:internal/modules/cjs/loader:1340:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
    at Module.load (node:internal/modules/cjs/loader:1207:32)
    at Module._load (node:internal/modules/cjs/loader:1023:12)
    at cjsLoader (node:internal/modules/esm/translators:345:17)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:294:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async importModuleDynamicallyWrapper (node:internal/vm/module:431:15)
    at async formattedImport (<X>\node_modules\.pnpm\mocha@10.3.0\node_modules\mocha\lib\nodejs\esm-utils.js:9:14)
    at async exports.requireOrImport (<X>\node_modules\.pnpm\mocha@10.3.0\node_modules\mocha\lib\nodejs\esm-utils.js:42:28)
    at async exports.loadFilesAsync (<X>\node_modules\.pnpm\mocha@10.3.0\node_modules\mocha\lib\nodejs\esm-utils.js:100:20)
    at async singleRun (<X>\node_modules\.pnpm\mocha@10.3.0\node_modules\mocha\lib\cli\run-helpers.js:125:3)
    at async exports.handler (<X>\node_modules\.pnpm\mocha@10.3.0\node_modules\mocha\lib\cli\run.js:370:5)