Skip to content

Module '".../node_modules/zod/index"' has no default export. import type z from 'zod'; #1032

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

Closed
1 task done
enricrp-rea opened this issue Sep 3, 2024 · 8 comments · Fixed by #1039
Closed
1 task done
Labels
bug Something isn't working

Comments

@enricrp-rea
Copy link

Confirm this is a Node library issue and not an underlying OpenAI API issue

  • This is an issue with the Node library

Describe the bug

I am programming an assistant using the openai library but when trying to build my code it gives the following error.

../../node_modules/openai/helpers/zod.d.ts:2:13 - error TS1192: Module '"../node_modules/zod/index"' has no default export.

2 import type z from 'zod';
              ~

  ../../node_modules/zod/index.d.ts:1:1
    1 export * from "./lib";
      ~~~~~~~~~~~~~~~~~~~~~~
    'export *' does not re-export a default.

[3:27:12 PM] Found 1 error. Watching for file changes.

Shouldn't it be better to import only the necessary types from zod instead of all types?

import type { infer as _infer, ZodType } from 'zod';

This way, it would benfit tree-shaking as we are only importing what we need.

To Reproduce

  1. Install the openai library
  2. Build node in watch mode

Code snippets

No response

OS

Ubuntu

Node version

v20.15.0

Library version

openai v4.56.0

@enricrp-rea enricrp-rea added the bug Something isn't working label Sep 3, 2024
@RobertCraigie
Copy link
Collaborator

This way, it would benfit tree-shaking as we are only importing what we need.

Tree-shaking shouldn't matter here as we're using the type import modifier which means that import is never included in the output JS in the first place.

I'm not sure why you're seeing a type error though, can you share your package.json, tsconfig etc?

@enricrp-rea
Copy link
Author

Of course!
base tsconfig

{
    "compilerOptions": {
        "target": "es2020",
        "module": "commonjs",
        "lib": ["es2020", "dom"],
        "allowJs": false,
        "declaration": true,
        "declarationMap": true,
        "sourceMap": true,
        "removeComments": true,
        "forceConsistentCasingInFileNames": true,
        "downlevelIteration": true,
        "strict": true,
        "moduleResolution": "node",
        "paths": {},
        "typeRoots": ["node_modules/@types"],
        "types": ["node"],
        "allowSyntheticDefaultImports": false,
        "experimentalDecorators": true,
        "emitDecoratorMetadata": true,
        "resolveJsonModule": true,
        "incremental": true,
        "strictBindCallApply": true,
        "strictFunctionTypes": true,
        "strictNullChecks": true,
        "strictPropertyInitialization": true,
        "noImplicitAny": true,
        "noImplicitThis": true,
        "noImplicitReturns": true,
        "noUnusedParameters": true,
        "noUnusedLocals": true,
        "noFallthroughCasesInSwitch": true,
        "preserveSymlinks": true,
        "suppressImplicitAnyIndexErrors": true
    },
    "exclude": ["node_modules"]
}

tsconfig

{
    "extends": "../../tsconfig.json",
    "ts-node": {
        "swc": true,
        "transpileOnly": true
    },
    "compilerOptions": {
        "declaration": false,
        "declarationMap": false,
        "allowJs": true,
        "checkJs": false,
        "outDir": "./dist",
        "baseUrl": "./",
        "types": ["node", "jest"],
        "paths": {
            "~api": ["src/app/api"]
        }
    },
    "include": [
        "src/**/*.ts",
        "src/**/*.js",
        "tsconfig.json",
        "jest.config.ts",
        ".eslintrc.js"
    ]
}

package.json

{
  "name": "our-project",
  "version": "1.0.0",
  "description": "Awesome project",
  "main": "dist/src/index.js",
  "scripts": {},
  "author": "me",
  "license": "ISC",
  "dependencies": {
  //  other libraries
    "openai": "^4.56.0",
    "zod": "^3.23.8"
  },
  "devDependencies": {
  //  other libraries
  },
  "repository": {
    "type": "git",
    "url": "url-that-leads-somewhere"
  }
}

@andreas-remente
Copy link

andreas-remente commented Sep 4, 2024

We're also getting this error in our Typescript project.

tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "out",
    "sourceMap": true,
    "strict": true,
    "target": "es2018",
    "allowJs": true,
    "strictNullChecks": true,
    "resolveJsonModule": true
  },
  "compileOnSave": true,
  "include": ["src"]
}

package.json

{
  "name": "project",
  "version": "1.0.0",
  "main": "out/src/index.js",
  "license": "UNLICENSED",
    "openai": "^4.57.1",
    "zod": "^3.23.8"
    // plus way too many other dependencies...
  },
  "private": true,
  "devDependencies": {
    // ...
  },
  "engines": {
    "node": "18"
  }
}

@RobertCraigie
Copy link
Collaborator

I haven't had a chance to test out the provided reproduction yet, would you be able to edit the installed package to verify if just importing the symbols needed fixes the issue?

@enricrp-rea
Copy link
Author

enricrp-rea commented Sep 4, 2024

@RobertCraigie yes, I did it yesterday and it solved the error when importing the needed symbols

import type { infer as _infer, ZodType } from 'zod';

I guess the problem is that zod library does not export a default (node_modules/zod/index.d.ts) and as the error sais, "export * does not re-export a default (export default z is located in node_modules/zod/lib/index.d.ts) so you need to import always the symbols you need. Or you could also import it as

import type * as z from 'zod';

@RobertCraigie
Copy link
Collaborator

Great thank you! Will have a fix out later today.

@enricrp-rea
Copy link
Author

thank you 👍

@RobertCraigie
Copy link
Collaborator

This should be fixed in v4.57.3!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants