content icon indicating copy to clipboard operation
content copied to clipboard

`bun install` always fails because of a dependency check bug

Open dannote opened this issue 4 months ago • 7 comments

Environment

  • Operating System: Darwin
  • Node Version: v20.9.0
  • Nuxt Version: 4.1.2
  • CLI Version: 3.28.0
  • Nitro Version: 2.12.6
  • Package Manager: [email protected]
  • Builder: -
  • User Config: modules, compatibilityDate, devtools, content
  • Runtime Modules: @nuxt/[email protected]
  • Build Modules: -

Version

v3.7.1

Reproduction

https://github.com/dannote/nuxt-content-reproduction

Description

The installation fails although zod is in my package.json:

$ bun install                                                                                                                           

bun install v1.2.22 (6bafe260)

$ nuxt prepare

 ERROR  It seems you are using Zod version 4 for collection schema, but Zod is not installed, Nuxt Content does not ship with zod, install zod and it will work.  12:04:38 AM

    at Object.toJSONSchema (node_modules/@nuxt/content/dist/module.mjs:198:13)
    at defineCollection (node_modules/@nuxt/content/dist/module.mjs:2283:32)
    at content.config.ts:7:44
    at async Function.import (node_modules/jiti/dist/jiti.cjs:1:202945)
    at async resolveConfig (node_modules/c12/dist/shared/c12.Bzgyhsy6.mjs:382:18)
    at async loadConfig (node_modules/c12/dist/shared/c12.Bzgyhsy6.mjs:169:23)
    at async Promise.all (index 0)
    at async loadContentConfig (node_modules/@nuxt/content/dist/module.mjs:2487:26)
    at async setup (node_modules/@nuxt/content/dist/module.mjs:2866:29)
    at async normalizedModule (node_modules/@nuxt/kit/dist/index.mjs:199:17)



 ERROR  It seems you are using Zod version 4 for collection schema, but Zod is not installed, Nuxt Content does not ship with zod, install zod and it will work.

Additional context

No response

Logs


dannote avatar Sep 18 '25 21:09 dannote

Have you tried removing lock file and node_modules and re-install? I did clone your repository but seems to work fine. I use [email protected] and [email protected]

farnabaz avatar Sep 19 '25 10:09 farnabaz

Yes, I did try removing the lock file and node_modules. I was also able to reproduce the issue in a new project (nuxt-content-reproduction). Maybe your Bun installation is finding zod somewhere outside the project's node_modules folder? I'll dig deeper and try to provide a better reproduction case.

dannote avatar Sep 19 '25 11:09 dannote

@farnabaz I tried monkey-patching node_modules/@nuxt/content/dist/module.mjs:

async function initiateValidatorsContext() {
  if (await isPackageInstalled("valibot") && await isPackageInstalled("@valibot/to-json-schema")) {
    nuxtContentContext$1().set("valibot", await import('./chunks/valibot.mjs'));
  }
  if (await isPackageInstalled("zod")) {
    nuxtContentContext$1().set("zod3", await Promise.resolve().then(function () { return zod3; }));
    nuxtContentContext$1().set("zod4", await import('./chunks/zod4.mjs'));
  }

  // Here
  console.log(nuxtContentContext$1().get('zod4').toJSONSchema.toString())
}

And here is the console output:

bun install v1.2.22 (6bafe260)

$ nuxt prepare
function toJSONSchema(_schema, name) {                                                                                                                             8:55:36 PM
  const schema = _schema;
  try {
    const baseSchema = z.toJSONSchema(schema, {
      target: "draft-7",
      unrepresentable: "any",
      override: (ctx) => {
        const def = ctx.zodSchema._zod?.def;
        if (def?.type === "date") {
          ctx.jsonSchema.type = "string";
          ctx.jsonSchema.format = "date-time";
        }
        if (def?.$content) {
          ctx.jsonSchema.$content = def.$content;
        }
      }
    });
    const draft07Schema = {
      $schema: "http://json-schema.org/draft-07/schema#",
      $ref: #/definitions/${name},
      definitions: {
        [name]: {
          type: baseSchema.type || "object",
          properties: baseSchema.properties || {},
          required: baseSchema.required || [],
          additionalProperties: typeof baseSchema.additionalProperties === "boolean" ? baseSchema.additionalProperties : false
        }
      }
    };
    return draft07Schema;
  } catch (error) {
    console.error(
      "Zod toJSONSchema error for schema:",
      schema.constructor.name,
      error
    );
    return {
      $schema: "http://json-schema.org/draft-07/schema#",
      $ref: #/definitions/${name},
      definitions: {
        [name]: {
          type: "object",
          properties: {},
          required: [],
          additionalProperties: false
        }
      }
    };
  }
}

 ERROR  It seems you are using Zod version 4 for collection schema, but Zod is not installed, Nuxt Content does not ship with zod, install zod and it will work.   8:55:36 PM

    at Object.toJSONSchema (node_modules/@nuxt/content/dist/module.mjs:198:13)
    at defineCollection (node_modules/@nuxt/content/dist/module.mjs:2285:32)
    at content.config.ts:7:44
    at async Function.import (node_modules/jiti/dist/jiti.cjs:1:202945)
    at async resolveConfig (node_modules/c12/dist/shared/c12.Bzgyhsy6.mjs:382:18)
    at async loadConfig (node_modules/c12/dist/shared/c12.Bzgyhsy6.mjs:169:23)
    at async Promise.all (index 0)
    at async loadContentConfig (node_modules/@nuxt/content/dist/module.mjs:2489:26)
    at async setup (node_modules/@nuxt/content/dist/module.mjs:2868:29)
    at async normalizedModule (node_modules/@nuxt/kit/dist/index.mjs:199:17)
    at async callModule (node_modules/@nuxt/kit/dist/index.mjs:765:202)
    at async installModules (node_modules/@nuxt/kit/dist/index.mjs:641:5)
    at async initNuxt (node_modules/nuxt/dist/index.mjs:5846:3)
    at async loadNuxt (node_modules/nuxt/dist/index.mjs:6063:5)
    at async loadNuxt (node_modules/@nuxt/kit/dist/index.mjs:947:16)
    at async Object.run (node_modules/@nuxt/cli/dist/chunks/prepare.mjs:32:18)
    at async runCommand (node_modules/citty/dist/index.mjs:316:16)
    at async runCommand (node_modules/citty/dist/index.mjs:307:11)
    at async runMain (node_modules/citty/dist/index.mjs:445:7)

It looks like Zod v4 is loaded, but the context is being overwritten by the default placeholder values.

dannote avatar Sep 19 '25 18:09 dannote

@dannote Could you try this monkey-patch: I suspect hat context is not shared between module and content.config.ts and therefore raise error.

Also how do you run the project? bun dev or bun --bun dev?

// Line 225 in node_modules/@nuxt/content/dist/module.mjs

ctx.set(nuxtContentContext);
// const nuxtContentContext$1 = ctx.use; // Comment this line and add below lines
globalThis.nuxtContentContext = globalThis.nuxtContentContext || nuxtContentContext;
const nuxtContentContext$1 = () => ({
  set: (key, value) => {
    nuxtContentContext[key] = value;
  },
  get: (key) => {
    return nuxtContentContext[key];
  }
})

farnabaz avatar Sep 22 '25 06:09 farnabaz

@farnabaz

Also how do you run the project? bun dev or bun –bun dev?

I run bun install, which in turn runs nuxt prepare. I also tried bunx --bun nuxt prepare now, and that worked, but bunx nuxt prepare fails with the same error as before ("It seems you are using Zod version 4...").

Could you try this monkey-patch

I tried it, but I still get the same error.

dannote avatar Sep 25 '25 13:09 dannote

Hi. I'm encountering the same issue, on pnpm and Node v22.17.0. Working with Turborepo, but the dependency is installed close to the content app.

cc @farnabaz

lukasborawski avatar Nov 10 '25 12:11 lukasborawski

@dannote Sorry for late response, If it works fine with bun --bun ... command as you said, it is not module's issue. In order to make sure that Nuxt runs inside bun environments you need to use --bun flag. Checkout Bun's official docs about Nuxt https://bun.com/docs/guides/ecosystem/nuxt

@lukasborawski Could you provide a reproduction for this issue, I believe it is different issue and not related to current one.

farnabaz avatar Dec 01 '25 17:12 farnabaz