Module '"zod"' has no exported member 'z'.ts
I get this error when my linter runs over the bunx create-t3-app starting repo. I also get this linting error when i install zod separately into a empty repo. The code runs fine tho. I don't know if I'm missing type deps or maybe the package has changed and all the tutorials telling me to import {z} from 'zod' are outdated now. How can i fix this error?
zod version: ^3.23.3 bun version: 1.1.17 node version: v20.12.2
package.json:
{
"name": "subhub",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"dev": "next dev",
"build": "next build",
"lint": "next lint",
"start": "next start",
"dev:soft-reset": "bun db:wipe && bun db:seed && bun dev",
"dev:hard-reset": "bun i && bun db:rm && bun db:start && bun db:seed && bun dev",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio",
"db:seed": "bun run src/server/db/seed.ts",
"db:wipe": "bun run src/server/db/wipe.ts",
"db:start": "./start-database.sh && sleep 10 && bun db:generate && bun db:migrate && bun db:push",
"db:stop": "docker stop $(docker ps -aq) || true",
"db:rm": "rm -rf drizzle || true && bun db:stop || true && docker rm $(docker ps -aq) || true",
"db:restart": "bun db:stop || true && bun db:rm || true && bun db:start"
},
"dependencies": {
"@auth/drizzle-adapter": "^1.1.0",
"@hookform/resolvers": "^3.9.0",
"@radix-ui/react-icons": "^1.3.0",
"@t3-oss/env-nextjs": "^0.10.1",
"@tanstack/react-query": "^5.50.0",
"@trpc/client": "^11.0.0-rc.446",
"@trpc/next": "^11.0.0-rc.446",
"@trpc/react-query": "^11.0.0-rc.446",
"@trpc/server": "^11.0.0-rc.446",
"@types/uuid": "^10.0.0",
"bcrypt": "^5.1.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"drizzle-orm": "^0.33.0",
"geist": "^1.3.0",
"lucide-react": "^0.438.0",
"next": "^14.2.4",
"next-auth": "^4.24.7",
"next-themes": "^0.3.0",
"postgres": "^3.4.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"recharts": "^2.12.7",
"superjson": "^2.2.1",
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7",
"uuid": "^10.0.0",
"zod": "^3.23.3"
},
"devDependencies": {
"@types/bcrypt": "^5.0.2",
"@types/eslint": "^8.56.10",
"@types/node": "^20.14.10",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"drizzle-kit": "^0.24.0",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.4",
"eslint-plugin-drizzle": "^0.2.3",
"postcss": "^8.4.39",
"prettier": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.5",
"tailwindcss": "^3.4.3",
"typescript": "^5.5.3"
},
"ct3aMetadata": {
"initVersion": "7.37.0"
}
}
Can you provide tsconfig.json
{
"compilerOptions": {
/* Base Options: */
"esModuleInterop": true,
"skipLibCheck": true,
"target": "ESNext",
"allowJs": true,
"resolveJsonModule": true,
"moduleDetection": "force",
"isolatedModules": true,
/* Strictness */
"strict": true,
"noUncheckedIndexedAccess": true,
"checkJs": true,
/* Bundled projects */
"lib": ["dom", "dom.iterable", "ESNext"],
"noEmit": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"jsx": "preserve",
"plugins": [{ "name": "next" }],
"incremental": true,
/* Path Aliases */
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"]
},
"types": ["cypress"]
},
"include": [
".eslintrc.cjs",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"**/*.cjs",
"**/*.js",
".next/types/**/*.ts"
],
"exclude": ["node_modules"]
}
I got the same error
{ "compilerOptions": { /* Base Options: */ "esModuleInterop": true, "skipLibCheck": true, "target": "ESNext", "allowJs": true, "resolveJsonModule": true, "moduleDetection": "force", "isolatedModules": true, /* Strictness */ "strict": true, "noUncheckedIndexedAccess": true, "checkJs": true, /* Bundled projects */ "lib": ["dom", "dom.iterable", "ESNext"], "noEmit": true, "module": "ESNext", "moduleResolution": "Bundler", "jsx": "preserve", "plugins": [{ "name": "next" }], "incremental": true, /* Path Aliases */ "baseUrl": ".", "paths": { "~/*": ["./src/*"] }, "types": ["cypress"] }, "include": [ ".eslintrc.cjs", "next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.cjs", "**/*.js", ".next/types/**/*.ts" ], "exclude": ["node_modules"] }
Can you try these settings?
{ "compilerOptions": { "target": "ESNext", "module": "ESNext", "allowImportingTsExtensions": true, "moduleResolution": "Bundler", "noEmit": true, "esModuleInterop": true, "strict": true } }
I am getting the same error from many days in the vs code.
when did you start getting it?- JacobOn Sep 12, 2024, at 09:03, Taksh Chanana @.***> wrote: I am getting the same error from many days in the vs code.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>
allowImportingTsExtensions
same
This fixes it for me:
in eslint.config.mjs, add the zod plugin:
import typescriptEslint from "@typescript-eslint/eslint-plugin";
import drizzle from "eslint-plugin-drizzle";
import zod from "eslint-plugin-zod";
import tsParser from "@typescript-eslint/parser";
import path from "node:path";
import { fileURLToPath } from "node:url";
import js from "@eslint/js";
import { FlatCompat } from "@eslint/eslintrc";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const compat = new FlatCompat({
baseDirectory: __dirname,
recommendedConfig: js.configs.recommended,
allConfig: js.configs.all
});
export default [...compat.extends(
"next/core-web-vitals",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
), {
plugins: {
"@typescript-eslint": typescriptEslint,
drizzle,
zod,
},
languageOptions: {
parser: tsParser,
ecmaVersion: 5,
sourceType: "script",
parserOptions: {
project: true,
},
},
rules: {
"zod/prefer-enum": 2,
"zod/require-strict": 2,
"@typescript-eslint/array-type": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@next/next/no-duplicate-head": "off",
"import/no-anonymous-default-export": "off",
"@typescript-eslint/consistent-type-imports": ["warn", {
prefer: "type-imports",
fixStyle: "inline-type-imports",
}],
"@typescript-eslint/no-unused-vars": ["warn", {
argsIgnorePattern: "^_",
}],
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-misused-promises": ["error", {
checksVoidReturn: {
attributes: false,
},
}],
"@typescript-eslint/no-empty-object-type": "off",
"drizzle/enforce-delete-with-where": ["error", {
drizzleObjectName: ["db", "ctx.db"],
}],
"drizzle/enforce-update-with-where": ["error", {
drizzleObjectName: ["db", "ctx.db"],
}],
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-argument": "off",
},
}];
Then install the dependencies:
bun add @eslint/js @eslint/eslintrc @typescript-eslint/parser @typescript-eslint/eslint-plugin eslint eslint-plugin-react eslint-plugin-jsx-a11y eslint-plugin-import eslint-plugin-drizzle eslint-plugin-zod
For reference, here's my package.json:
{
"name": "aii",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"build": "next build",
"db:generate": "drizzle-kit generate",
"db:migrate": "drizzle-kit migrate",
"db:push": "drizzle-kit push",
"db:studio": "drizzle-kit studio",
"db:seed": "bun run src/server/db/seed.ts",
"dev": "next dev",
"lint": "next lint",
"start": "next start"
},
"dependencies": {
"@auth/drizzle-adapter": "^1.1.0",
"@fullcalendar/daygrid": "^6.1.15",
"@fullcalendar/interaction": "^6.1.15",
"@fullcalendar/react": "^6.1.15",
"@hookform/resolvers": "^3.9.0",
"@radix-ui/react-alert-dialog": "^1.1.1",
"@radix-ui/react-collapsible": "^1.1.0",
"@radix-ui/react-context-menu": "^2.2.1",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-hover-card": "^1.1.1",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.1.0",
"@radix-ui/react-menubar": "^1.1.1",
"@radix-ui/react-progress": "^1.1.0",
"@radix-ui/react-select": "^2.1.1",
"@radix-ui/react-separator": "^1.1.0",
"@radix-ui/react-slider": "^1.2.0",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-switch": "^1.1.0",
"@radix-ui/react-tabs": "^1.1.0",
"@radix-ui/react-toggle": "^1.1.0",
"@radix-ui/react-toggle-group": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.2",
"@sendgrid/mail": "^8.1.3",
"@t3-oss/env-nextjs": "^0.10.1",
"@tanstack/react-query": "^5.50.0",
"@trpc/client": "^11.0.0-rc.446",
"@trpc/next": "^11.0.0-rc.446",
"@trpc/react-query": "^11.0.0-rc.446",
"@trpc/server": "^11.0.0-rc.446",
"bcrypt": "^5.1.1",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"drizzle-orm": "^0.33.0",
"eslint-plugin-import": "^2.30.0",
"eslint-plugin-jsx-a11y": "^6.10.0",
"eslint-plugin-react": "^7.36.1",
"geist": "^1.3.0",
"lucide-react": "^0.441.0",
"next": "^14.2.4",
"next-auth": "^4.24.7",
"node-cron": "^3.0.3",
"nodemailer": "^6.9.15",
"postgres": "^3.4.4",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.53.0",
"superjson": "^2.2.1",
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7",
"zod": "^3.23.8"
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.10.0",
"@types/bcrypt": "^5.0.2",
"@types/eslint": "^8.56.10",
"@types/node": "^20.14.10",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^8.6.0",
"@typescript-eslint/parser": "^8.6.0",
"drizzle-kit": "^0.24.0",
"eslint": "^9.10.0",
"eslint-config-next": "^14.2.4",
"eslint-plugin-drizzle": "^0.2.3",
"eslint-plugin-zod": "^1.4.0",
"postcss": "^8.4.39",
"prettier": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.5",
"tailwindcss": "^3.4.3",
"typescript": "^5.5.3"
},
"ct3aMetadata": {
"initVersion": "7.37.0"
}
}
Okay so for those of us who don't have any linting rules and have this stupid error, what the heck is it
yeah linting configuration didn’t actually fix it for me either- JacobOn Sep 24, 2024, at 23:13, ZachHandley @.***> wrote: Okay so for those of us who don't have any linting rules and have this stupid error, what the heck is it
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>
@colinhacks can you please fix this or look at this, something got effed
❯ bun install
bun install v1.1.30-canary.34 (17d719fa)
+ [email protected]
+ @astrojs/[email protected]
+ @astrojs/[email protected]
+ @astrojs/[email protected]
+ @astrojs/[email protected]
+ @astrojs/[email protected]
+ @astrojs/[email protected]
+ @directus/[email protected]
+ @iconify/[email protected]
+ @inox-tools/[email protected]
+ @nanostores/[email protected]
+ @nanostores/[email protected]
+ @vueuse/[email protected]
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
+ [email protected]
865 packages installed [164.71s]
okay great, so it's installed right? and I can use it right?
okay............................................. idk what the hell to do here. No package manager properly resolves it and it's broken now on multiple projects.
i should clarify that this is not a eslint error. because even if i get eslint to shut up next build still fails
^ correct. Something got effed.
I have the same issue with Typescript 5.6, but it works fine with Typescript 5.5.
I suspect the problem is related to this change (related Typescript pull request). This change was already in the [email protected] prerelease, and I'm also encountering the issue when using this version.
I fixed above issue by putting the following inside the tsconfig.json for your front end project NOT Amplify file:
{
"compilerOptions": {
...
"esModuleInterop": true
...
}
}
- Add this to your package.json dependency (^ is the problem)
"zod": "3.22.4"
- Remove node_modules(
sudo rm -rf node_modules) - Re-install npm modules (
npm i)
careful with the sudo rm- JacobOn Oct 9, 2024, at 15:52, Taksh Chanana @.***> wrote:
Add this to your package.json dependency (^ is the problem)
"zod": "3.22.4"
Remove node_modules(sudo rm -rf node_modules) Re-install npm modules (npm i)
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>
- Add this to your package.json dependency (^ is the problem)
^ is not the problem. ^ merely allows to get the newest 3.x.x version out there. The real problem is the specific version ^3 gets you and since I just installed zod in my new project my version looks like this "zod":"^3.23.8. Removing the ^ does literally nothing in my case.
But sure, I installed v3.22.4 and it worked, so then I kept upgrading zod until it broke. v3.23.7 works and v3.23.8 doesnt.
Also, v3.23.8 works with commonjs. It's just the ESM part that's broken.
any update on the issue ? using pnpm instead of bun seems to resolve the issue.
hmm thank u ill stick with pnpm then- JacobOn Nov 12, 2024, at 03:22, catinrage @.***> wrote: any update on the issue ? using pnpm instead of bun seems to resolve the issue.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: @.***>
I have the same issue with Typescript 5.6, but it works fine with Typescript 5.5.
I suspect the problem is related to this change (https://github.com/microsoft/TypeScript/pull/58825). This change was already in the [email protected] prerelease, and I'm also encountering the issue when using this version.
Rolling back from [email protected] to [email protected] fixed the compilation error on my side
npm install --save-dev [email protected]
I fixed it with "allowSyntheticDefaultImports" in tsconfig.json
{
"compilerOptions": {
...
"allowSyntheticDefaultImports": true,
...
}
}
But sure, I installed v3.22.4 and it worked, so then I kept upgrading zod until it broke. v3.23.7 works and v3.23.8 doesnt.
Also, v3.23.8 works with commonjs. It's just the ESM part that's broken.
confirmed 3.23.7 works
Solved this issue (TS2305) by changing moduleResolution using bundler instead of nodenext in the tsconfig.json. Using version 3.24.1
I was facing this issue with [email protected] with the following in my tsconfig.json which were autocompleted options when making the default output of tsc --init to be more ESMy.
{
[...]
"target": "ESNext"
"module": "ESNext",
"moduleResolution": "nodenext",
}
On hover, VSCode warned me about "module": "ESNext",
Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'.
So I changed it to...
{
[...]
"target": "ESNext"
"module": "NodeNext",
"moduleResolution": "nodenext",
}
...and now code runs and also doesn't redline in the VSCode editor.
My full tsconfig.json ...
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig to read more about this file */
/* Projects */
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "ESNext" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
/* Modules */
"module": "NodeNext" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "nodenext", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
// "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
// "rewriteRelativeImportExtensions": true, /* Rewrite '.ts', '.tsx', '.mts', and '.cts' file extensions in relative import paths to their JavaScript equivalent in output files. */
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
// "noUncheckedSideEffectImports": true, /* Check side effect imports. */
// "resolveJsonModule": true, /* Enable importing .json files. */
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
/* JavaScript Support */
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
/* Emit */
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
/* Type Checking */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
I tried the below and got the issue resolved
rm -rf node_modules
npm i zod-to-json-schema
upgrading zod to the latest version also resolve the issue.
I tried the below and got the issue resolved
rm -rf node_modules npm i zod-to-json-schema
Nice, this fixed it for me as well (using Bun instead), ty!
rm -rf node_modules
bun i zod-to-json-schema
Hi @cefn! I'm Dosu and I’m helping the zod team.
You're right—setting "module": "NodeNext" with "moduleResolution": "nodenext" in your tsconfig.json is the correct fix for this error with Zod and TypeScript 5.6+ ESM projects. This is needed because TypeScript 5.6 changed how it interprets the "type" field in package.json and file extensions for modules in node_modules, which affects how ESM and CommonJS modules are resolved. If these settings don't match, TypeScript can't properly resolve Zod's exports, leading to the "no exported member 'z'" error.
For best compatibility, use import * as z from "zod" or import z from "zod" instead of import { z } from "zod"—the latter can break in some environments, especially with certain Zod versions or bundlers [source].
If you run into other module resolution issues (especially in monorepos or with Turbopack), make sure Zod and your tooling are up to date, and check out related discussions for more context:
- TypeScript 5.6 module resolution changes
- Zod module resolution issues and fixes
- Recent Zod export structure changes
If this solves your problem, please close the issue!
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other