Skip to content

fix(metadata): add "type": "module" to fix ERR_MODULE_NOT_FOUND on Vercel - #977

Merged
hotlong merged 2 commits into
mainfrom
copilot/fix-module-not-found-error-another-one
Mar 23, 2026
Merged

hotlong merged 2 commits into
mainfrom
copilot/fix-module-not-found-error-another-one

Conversation

Copilot AI commented Mar 23, 2026 •

Copy link
Copy Markdown
Contributor

Vercel serverless runtime resolves @objectstack/metadata to src/index.ts instead of compiled dist/ output, causing ERR_MODULE_NOT_FOUND at runtime in apps/studio/api/index.js.

Changes

  • packages/metadata/package.json: Add "type": "module" and update exports from .mjs/.js to .js/.cjs — aligning with @objectstack/core, @objectstack/runtime, and @objectstack/rest which all resolve correctly on Vercel
+  "type": "module",
   "exports": {
     ".": {
-      "import": "./dist/index.mjs",
-      "require": "./dist/index.js"
+      "import": "./dist/index.js",
+      "require": "./dist/index.cjs"
     },

All 154 metadata tests and 13 studio tests pass. Build output verified: tsup correctly emits .js (ESM) and .cjs (CJS) with "type": "module".

Original prompt

2026-03-23 16:57:03.244 [error] Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/apps/studio/node_modules/@objectstack/metadata/src/index.ts' imported from /var/task/apps/studio/api/index.js
at finalizeResolution (node:internal/modules/esm/resolve:280:11)
at moduleResolve (node:internal/modules/esm/resolve:870:10)
at moduleResolveWithNodePath (node:internal/modules/esm/resolve:996:14)
at defaultResolve (node:internal/modules/esm/resolve:1039:79)
at #cachedDefaultResolve (node:internal/modules/esm/loader:718:20)
at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:735:38)
at ModuleLoader.resolveSync (node:internal/modules/esm/loader:764:52)
at #resolve (node:internal/modules/esm/loader:700:17)
at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:620:35)
at ModuleJob.syncLink (node:internal/modules/esm/module_job:143:33) {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///var/task/apps/studio/node_modules/@objectstack/metadata/src/index.ts'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/var/task/apps/studio/node_modules/@objectstack/metadata/src/index.ts' imported from /var/task/apps/studio/api/index.js
at finalizeResolution (node:internal/modules/esm/resolve:280:11)
at moduleResolve (node:internal/modules/esm/resolve:870:10)
at moduleResolveWithNodePath (node:internal/modules/esm/resolve:996:14)
at defaultResolve (node:internal/modules/esm/resolve:1039:79)
at #cachedDefaultResolve (node:internal/modules/esm/loader:718:20)
at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:735:38)
at ModuleLoader.resolveSync (node:internal/modules/esm/loader:764:52)
at #resolve (node:internal/modules/esm/loader:700:17)
at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:620:35)
at ModuleJob.syncLink (node:internal/modules/esm/module_job:143:33) {
code: 'ERR_MODULE_NOT_FOUND',
url: 'file:///var/task/apps/studio/node_modules/@objectstack/metadata/src/index.ts'
}
Node.js process exited with exit status: 1. The logs above can help with debugging the issue.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel

vercel Bot commented Mar 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
spec Ignored Ignored Mar 23, 2026 5:18pm

Request Review

@vercel

vercel Bot commented Mar 23, 2026

Copy link
Copy Markdown

Deployment failed with the following error:

Environment Variable "TURSO_DATABASE_URL" references Secret "turso_database_url", which does not exist.

Learn More: https://vercel.com/docs/environment-variables

…OT_FOUND on Vercel

Convert @objectstack/metadata to "type": "module" to align with @objectstack/core,
@objectstack/runtime, and @objectstack/rest. Updates exports from .mjs/.js to .js/.cjs
pattern to ensure proper ESM resolution in Vercel serverless functions.

Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
Agent-Logs-Url: https://github.com/objectstack-ai/spec/sessions/b01a87bf-6ae6-4372-a353-df7cb055f1ec
Copilot AI changed the title [WIP] Fix module not found error in studio API fix(metadata): add "type": "module" to fix ERR_MODULE_NOT_FOUND on Vercel Mar 23, 2026
Copilot AI requested a review from hotlong March 23, 2026 17:21
@hotlong
hotlong marked this pull request as ready for review March 23, 2026 17:30
Copilot AI review requested due to automatic review settings March 23, 2026 17:30
@hotlong
hotlong merged commit b193de5 into main Mar 23, 2026
2 of 3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a Vercel runtime resolution issue where @objectstack/metadata was being resolved to src/index.ts instead of the compiled dist/ output by aligning the package’s ESM/CJS metadata with the rest of the monorepo packages that work correctly on Vercel.

Changes:

  • Added "type": "module" to @objectstack/metadata and updated exports to use the .js (ESM) / .cjs (CJS) pattern.
  • Added a changelog entry documenting the Vercel ERR_MODULE_NOT_FOUND fix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/metadata/package.json Switches the package to ESM via "type": "module" and updates exports mappings to point to the correct compiled artifacts (.js/.cjs).
packages/metadata/CHANGELOG.md Documents the runtime fix for Vercel module resolution.


### Patch Changes

- Fix ERR_MODULE_NOT_FOUND on Vercel: add `"type": "module"` and update exports to use `.js`/`.cjs` pattern (consistent with @objectstack/core, @objectstack/runtime)

Copilot AI Mar 23, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline code snippet in the changelog includes escaped quotes (\"type\": \"module\"), which will render the backslashes in Markdown. Use unescaped quotes inside the backticks so it displays as "type": "module" without backslashes in the rendered output.

Copilot uses AI. Check for mistakes.
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

Successfully merging this pull request may close these issues.

3 participants