adapters-vite / adapters: CommonJS type declarations import Vite's ESM-only types, so a CommonJS consumer gets TS1479

Open
#115 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
54/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, typescript, vite

Research direction

Start by inspecting the published .d.cts declarations for @openzeppelin/adapters-vite and the six adapters’ vite-config entries, then trace how the declaration build uses tsdown and rolldown-plugin-dts. Check whether an upstream bundler option preserves the import type resolution attribute, and add the proposed CommonJS type-check probe for each entry. Done means all seven probes pass under node16 with skipLibCheck: false.

Written by the indexing model from the issue text.

Description

What happens

The CommonJS declaration files of seven published entries import types from vite, and Vite publishes its types as ES modules only:

  • @openzeppelin/adapters-vite: dist/index.d.cts imports Plugin, PluginOption and UserConfig (checked in the published 15.0.0).
  • The vite-config entry of six adapters, each dist/vite-config.d.cts importing UserConfig (Midnight's also Plugin): adapter-stellar (checked in the published 6.0.2), adapter-evm, adapter-evm-core, adapter-midnight, adapter-polkadot, adapter-solana.

A consumer file that is CommonJS, imports one of these entries, and type-checks with "module": "node16" or "node18" (or "nodenext" before TypeScript 5.8) and skipLibCheck: false gets TS1479, reported inside the package's .d.cts, for example at dist/vite-config.d.cts(1,28). Since TypeScript 5.8, nodenext accepts a require of an ES module, so that setting no longer errors.

Run-time behavior is not affected. It is a type-check error only.

Why it matters

  • The packages ship a require condition with its own types, so they claim to support CommonJS consumers. For these entries the types do not hold under the settings above.
  • The error points into node_modules, at a file the consumer cannot edit, and does not say what to do.
  • Workarounds exist (an .mts Vite config, a .ts config in a "type": "module" package, or skipLibCheck: true), but each consumer has to find them.

Suggested fix

The declaration a CommonJS consumer needs is import type { UserConfig } from 'vite' with { 'resolution-mode': 'import' }. A hand-written .d.cts in that form passes. The build does not produce it today (tsdown 0.19 with rolldown-plugin-dts):

  • Written that way in source, the bundler emits the import without type, and under node16 that is TS2823.
  • The inline form, import('vite', { with: { 'resolution-mode': 'import' } }).UserConfig, is hoisted to a plain import * as … from "vite", which drops the attribute, and TS1479 comes back.

So the options are:

  1. A post-build step that rewrites the vite import in each .d.cts to the import type … with { 'resolution-mode': 'import' } form.
  2. A declaration bundler, or bundler version or setting, that keeps import type together with its attribute. Worth checking upstream first, since it would need no custom step.

Either way, fix all seven entries together. Consumers that build through adapters-vite would otherwise still get the error from that package. Add a type-check probe per entry (a CommonJS file under node16, skipLibCheck: false) to the dist checks so it stays fixed.

Not suggested: replacing UserConfig with a local structural type. It changes the declared return type of the adapters' config functions, and adapters-vite exposes Vite types in its public API, so it cannot work there.

Dominant language
TypeScript
Stars
2
Forks
2
Avg merge
6h 33m
Merged PRs (30d)
11

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OpenZeppelin/openzeppelin-adapters

All issues in OpenZeppelin/openzeppelin-adapters

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.