core icon indicating copy to clipboard operation
core copied to clipboard

Build error with @nuxthub/core on Nuxt 4 — Rollup "default" is not exported by node:path?commonjs-external

Open tapitapeh opened this issue 2 months ago • 3 comments

Describe the bug Build fails for a fresh Nuxt 4 project after adding nuxthub/core, even when not enabling the database.

Steps to reproduce Steps to reproduce the behavior:

  1. Create a new Nuxt 4 project
npm create nuxt@latest
  1. Add Nuxthub and wrangler
npx nuxi module add hub
pnpm add -D wrangler
  1. (Option A) Enable database in nuxt.config
export default defineNuxtConfig({
  hub: { database: true }
})

or (Option B) Simply include @nuxthub/core in modules without enabling the database.

  1. Build
npm run build
  1. See error

Expected behavior The project should build successfully with Nitro (Cloudflare Pages preset), regardless of whether hub: { database: true } is enabled.

Logs / error output

[8:03:14 AM] ✔ Client built in 801ms
[8:03:14 AM] ℹ Building server...
[8:03:14 AM] ℹ vite v7.1.11 building SSR bundle for production...
[8:03:15 AM] ℹ ✓ 53 modules transformed.
[8:03:15 AM] ℹ ✓ built in 321ms
[8:03:15 AM] ✔ Server built in 325ms
[nitro 8:03:15 AM] ✔ Generated public dist
[nuxt:hub 8:03:15 AM] ℹ Skipping bundling database migrations - no migrations found
[nitro 8:03:15 AM] ℹ Building Nuxt Nitro server (preset: cloudflare-pages, compatibility date: 2025-07-15)
node_modules/mime/dist/src/Mime.js (1:30): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
node_modules/mime/dist/src/Mime.js (1:38): The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten
node_modules/anymatch/node_modules/picomatch/lib/constants.js (2:7): Error when using sourcemap for reporting an error: Can't resolve original location of error.

[nitro 8:03:16 AM]  ERROR  RollupError: node_modules/anymatch/node_modules/picomatch/lib/constants.js (2:7): "default" is not exported by "node:path?commonjs-external", imported by "node_modules/anymatch/node_modules/picomatch/lib/constants.js".


1: import * as commonjsHelpers from "commonjsHelpers.js";
2: import require$$0 from "\u0000node:path?commonjs-external";
          ^
3: 
4: 'use strict';


[8:03:16 AM]  ERROR  node_modules/anymatch/node_modules/picomatch/lib/constants.js (2:7): "default" is not exported by "node:path?commonjs-external", imported by "node_modules/anymatch/node_modules/picomatch/lib/constants.js".

    at getRollupError (node_modules/rollup/dist/es/shared/parseAst.js:401:41)
    at error (node_modules/rollup/dist/es/shared/parseAst.js:397:42)
    at Module.error (node_modules/rollup/dist/es/shared/node-entry.js:16939:16)
    at Module.traceVariable (node_modules/rollup/dist/es/shared/node-entry.js:17391:29)
    at ModuleScope.findVariable (node_modules/rollup/dist/es/shared/node-entry.js:15061:39)
    at Identifier.bind (node_modules/rollup/dist/es/shared/node-entry.js:5413:40)
    at VariableDeclarator.bind (node_modules/rollup/dist/es/shared/node-entry.js:2804:23)
    at VariableDeclaration.bind (node_modules/rollup/dist/es/shared/node-entry.js:2800:28)
    at Program.bind (node_modules/rollup/dist/es/shared/node-entry.js:2800:28)
    at Module.bindReferences (node_modules/rollup/dist/es/shared/node-entry.js:16918:18)
    at Graph.sortModules (node_modules/rollup/dist/es/shared/node-entry.js:22721:20)
    at Graph.build (node_modules/rollup/dist/es/shared/node-entry.js:22619:14)
    at async node_modules/rollup/dist/es/shared/node-entry.js:23310:13
    at async catchUnfinishedHookActions (node_modules/rollup/dist/es/shared/node-entry.js:22780:16)
    at async rollupInternal (node_modules/rollup/dist/es/shared/node-entry.js:23305:5)
    at async buildProduction (node_modules/nitropack/dist/core/index.mjs:1607:19)
    at async node_modules/nuxt/dist/index.mjs:4681:5
    at async build (node_modules/nuxt/dist/index.mjs:7365:3)
    at async Object.run (node_modules/@nuxt/cli/dist/chunks/build.mjs:78:5)
    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) 



[8:03:16 AM]  ERROR  node_modules/anymatch/node_modules/picomatch/lib/constants.js (2:7): "default" is not exported by "node:path?commonjs-external", imported by "node_modules/anymatch/node_modules/picomatch/lib/constants.js".

Additional context

  • The error sometimes occurs even without enabling hub.database, just by including @nuxthub/core in modules.
  • The error path references anymatch → picomatch → node:path commonjs external. Might be an ESM/CJS interop issue in the Cloudflare Pages/Nitro/rollup pipeline with certain dependency versions.
  • No database migrations present (as expected for fresh project).

tapitapeh avatar Oct 21 '25 01:10 tapitapeh

I have the same issue too

linzhe141 avatar Oct 22 '25 05:10 linzhe141

We've created a fix in #672. Please could you let us know whether it resolves the issue by testing it with npm i https://pkg.pr.new/@nuxthub/core@672?

RihanArfan avatar Oct 22 '25 12:10 RihanArfan

We've created a fix in #672. Please could you let us know whether it resolves the issue by testing it with npm i https://pkg.pr.new/@nuxthub/core@672?

@RihanArfan for me it did not help. The only workaround I found is to add override of picomatch to my package.json.

ExEr7um avatar Oct 23 '25 18:10 ExEr7um

The issue has been fixed upstream

RihanArfan avatar Dec 11 '25 02:12 RihanArfan