Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module '"zod"' has no exported member 'z'.ts #3739

Open
JacobFV opened this issue Sep 5, 2024 · 25 comments
Open

Module '"zod"' has no exported member 'z'.ts #3739

JacobFV opened this issue Sep 5, 2024 · 25 comments

Comments

@JacobFV
Copy link

JacobFV commented Sep 5, 2024

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"
  }
}
@Char99s
Copy link

Char99s commented Sep 11, 2024

Can you provide tsconfig.json

@JacobFV
Copy link
Author

JacobFV commented Sep 11, 2024

{
  "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"]
}

@yycheng-hkuspace
Copy link

I got the same error

@Char99s
Copy link

Char99s commented Sep 12, 2024

{
  "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 } }

@takshch
Copy link

takshch commented Sep 12, 2024

I am getting the same error from many days in the vs code.

@JacobFV
Copy link
Author

JacobFV commented Sep 12, 2024 via email

@takshch
Copy link

takshch commented Sep 12, 2024

Screenshot from 2024-09-12 19-35-11

@JacobFV
Copy link
Author

JacobFV commented Sep 17, 2024

allowImportingTsExtensions

same

@JacobFV
Copy link
Author

JacobFV commented Sep 17, 2024

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"
  }
}

@ZachHandley
Copy link

Okay so for those of us who don't have any linting rules and have this stupid error, what the heck is it

@JacobFV
Copy link
Author

JacobFV commented Sep 25, 2024 via email

@ZachHandley
Copy link

ZachHandley commented Sep 25, 2024

@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?
image

okay............................................. idk what the hell to do here. No package manager properly resolves it and it's broken now on multiple projects.

@JacobFV
Copy link
Author

JacobFV commented Sep 25, 2024

i should clarify that this is not a eslint error. because even if i get eslint to shut up next build still fails

@ZachHandley
Copy link

ZachHandley commented Sep 25, 2024

^ correct. Something got effed.

@g-pascal
Copy link

g-pascal commented Oct 6, 2024

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.

@navneetsingh-cpu
Copy link

navneetsingh-cpu commented Oct 6, 2024

I fixed above issue by putting the following inside the tsconfig.json for your front end project NOT Amplify file:

{
  "compilerOptions": {
    ...
    "esModuleInterop": true
    ...
  }
}

@takshch
Copy link

takshch commented Oct 9, 2024

  1. Add this to your package.json dependency (^ is the problem)
"zod": "3.22.4"
  1. Remove node_modules(sudo rm -rf node_modules)
  2. Re-install npm modules (npm i)

@JacobFV
Copy link
Author

JacobFV commented Oct 11, 2024 via email

@igoro00
Copy link

igoro00 commented Oct 26, 2024

  1. 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.

@catinrage
Copy link

any update on the issue ? using pnpm instead of bun seems to resolve the issue.

@JacobFV
Copy link
Author

JacobFV commented Nov 12, 2024 via email

@fcamblor
Copy link

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 (microsoft/TypeScript#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]

@laureatresilience
Copy link

laureatresilience commented Dec 19, 2024

I fixed it with "allowSyntheticDefaultImports" in tsconfig.json

{
  "compilerOptions": {
    ...
    "allowSyntheticDefaultImports": true,
    ...
  }
}

@DanielViglione
Copy link

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

@zachary95
Copy link

Solved this issue (TS2305) by changing moduleResolution using bundler instead of nodenext in the tsconfig.json. Using version 3.24.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests