ensdomains / thorin

A web3 native design system.
https://thorin.pages.dev
MIT License
83 stars 21 forks source link

update exports for types #134

Open PaoloRollo opened 11 months ago

PaoloRollo commented 11 months ago

Importing @ensdomains/thorin returns the following error:

Could not find a declaration file for module '@ensdomains/thorin'. 'PROJECT_DIR/node_modules/@ensdomains/thorin/dist/index.es.js' implicitly has an 'any' type.
There are types at 'PROJECT_DIR/node_modules/@ensdomains/thorin/dist/types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The '@ensdomains/thorin' library may need to update its package.json or typings.

It seems it's unable to resolve the types defined in the package.json file. A possibile solution is the proposed one, where the types are set explicitly in the exports.".".import.types field:

"import": {
    "types": "./dist/types/index.d.ts",
    "default": "./dist/index.es.js"
}

For reference the tsconfig.json file used is the default one from Next.js:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": ["./*"]
    },
    "forceConsistentCasingInFileNames": true
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}
PaoloRollo commented 11 months ago

It seems to be connected to the moduleResolution property in the tsconfig.json file. Using node instead of the default bundler the package works fine