8000 Provide some option to set `moduleResolution` to `node16` with CJS build · Issue #62 · colinhacks/zshy · GitHub
[go: up one dir, main page]

Skip to content

Provide some option to set moduleResolution to node16 with CJS build #62

Open

Description

@rlj1202

Recent node.js versions can understand conditional exports and subpath exports in package.json. And there are many packages using it even though it is commonjs-only. To use those exports in commonjs, moduleResolution need to be at least node16.

Recently I encountered this error when building using zshy with @opentelemetry/semantic-conventions/incubating.

  There are types at '.../node_modules/@opentelemetry/semantic-conventions/build/src/index-incubating.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

... } from '@opentelemetry/semantic-conventions/incubating';

So... could this kind of option be added?

{
  "zshy": {
+   "cjs": "node16" // can be one of `true`, `false` and `"node16"`
}

Activity

  1. boneskull commented on Jan 11, 2026

    @boneskull

    I went into zshy and changed this behavior, but the tests are failing because it inhibits relative imports without file extensions, which is quite common in CJS projects. That being said, you're supposed to be writing with ESM in mind if you want to use zshy, so I'm not really clear on why this is a concern.

    The worst symptom, though, may be that zshy won't build a project that imports (via package.json exports) from another project built with zshy which seems ...bad. Neither Node.js nor TS (with appropriate moduleResolution) prevents this sort of require('package/exportName') in CJS from happening.

    Attempting to use the module's real path (e.g., whatever @opentelementry/semantic-conventions/incubating points to, with file extension) could work for CJS (untested), but such an import seems like it'd break ESM because Node.js won't allow such a thing.

    Setting module to CommonJS and moduleResolution to Node10 sure looks intentional though. Would need @colinhacks to weigh in here.

    Workaround: don't try to import from paths defined in package.json's exports field; stick to importing from main. Not always doable, though--especially if the package you're trying to import from ain't yours!

    Eager to send a PR to address this, if it would be accepted. Either breaking change or opt-in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0