Skip to content

Conversation

@alexandre-abrioux
Copy link
Contributor

@alexandre-abrioux alexandre-abrioux commented Jun 6, 2025

Issue

In CommonJS projects that use nodenext or node16 as moduleResolution, importing the @bonfida/spl-name-service library is impossible. We encounter the following error:

error TS2305: Module '"@bonfida/spl-name-service"' has no exported member [... name of the module ...]

The issue is also described in #105.

Context

With nodenext and node16 for moduleResolution—which is now the value recommended by TypeScript as classic and ndoe10 are deprecated—TypeScript interprets dist files dependending on their extension (.cjs/.d.cts/.mjs/.d.mts), or depending on the library's type (commonjs/module) for .js/.d.ts dist files.

Cause

@bonfida/spl-name-service exports JavaScript files with correct extensions (.cjs/.mjs), but the types are only exported as .d.ts, so can only be interpreted as ESM because the library's type is module.

"type": "module",

This explains why TypeScript cannot load @bonfida/spl-name-service in a CommonJS project with nodenext and node16 for moduleResolution.

You can verify the issue by using the arethetypeswrong tool available at this URL:
https://arethetypeswrong.github.io/?p=%40bonfida%2Fspl-name-service%403.0.11
(see the "Masquerading as ESM warning")

image

Solution

To keep it simple, everything is now exported as .js/.d.ts in their respective directory (dist/esm and dist/csj). For CommonJS, we create a simple dist/cjs/package.json file that contains the following:

{
  "type": "commonjs"
}

; this way, both the source code and types are interpreted correctly.

Here is the result of arethetypeswrong after the change:
image

Reference

@fm2055
Copy link
Contributor

fm2055 commented Aug 21, 2025

@alexandre-abrioux This has been merged into the latest release, thank you for your contribution.

@fm2055 fm2055 merged commit 7efd972 into SolanaNameService:main Aug 21, 2025
4 checks passed
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