Skip to content

fix: correct node/package.json main field to existing index.mjs#1418

Open
cybermanhao wants to merge 1 commit intogoogleapis:mainfrom
cybermanhao:fix/node-subpackage-main-field
Open

fix: correct node/package.json main field to existing index.mjs#1418
cybermanhao wants to merge 1 commit intogoogleapis:mainfrom
cybermanhao:fix/node-subpackage-main-field

Conversation

@cybermanhao
Copy link
Copy Markdown

Problem

node/package.json has:

{ "main": "../dist/node/index.js" }

But dist/node/index.js does not exist. The actual files present are:

  • dist/node/index.mjs
  • dist/node/index.cjs

Impact

Most environments are unaffected because Node.js and modern bundlers (webpack, rollup, etc.) resolve @google/genai/node via the parent package exports field, which correctly maps to index.mjs/index.cjs.

However, tools that fall back to subdirectory package.json main fields — such as tsx's custom ESM resolver — will encounter a Cannot find module error:

Error: Cannot find module '.../node_modules/@google/genai/dist/node/index.js'

Fix

Point main to the file that actually exists:

{ "main": "../dist/node/index.mjs" }

Notes

  • The root cause of the user-visible error is in tsx's resolveDirectory bypassing the parent package exports map — that is a separate issue in tsx
  • This fix makes the main field consistent with reality, which is a defensive improvement regardless

The main field pointed to ../dist/node/index.js which does not exist.
Only index.mjs and index.cjs are present in dist/node/.

This causes resolution failures in tools (e.g. tsx) that fall back to
the subdirectory package.json main field instead of reading the parent
package exports map.
@google-cla
Copy link
Copy Markdown

google-cla bot commented Mar 18, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

2 participants