react-square-web-payments-sdk icon indicating copy to clipboard operation
react-square-web-payments-sdk copied to clipboard

Typing with CJS and ESM interop are still incompatible

Open samesfahani-tuplehealth opened this issue 10 months ago • 3 comments

Describe the bug

Error:

Could not find a declaration file for module 'react-square-web-payments-sdk'. 'stackblitz:/node_modules/react-square-web-payments-sdk/dist/index.es.js' implicitly has an 'any' type.
  There are types at 'stackblitz:/node_modules/react-square-web-payments-sdk/dist/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'react-square-web-payments-sdk' library may need to update its package.json or typings.(7016)

Required readings: https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md#common-causes https://arethetypeswrong.github.io/?p=react-square-web-payments-sdk%403.2.1

It seems like the proper declaration for typing in package.json should be something like this with the types attribute completely removed:

  "exports": {
    ".": {
      "require": {
        "default": "./dist/index.cjs.js",
        "types": "./dist/index.d.ts"
      },
      "import": {
        "default": "./dist/index.es.mjs",
        "types": "./dist/index.d.mts"
      }
    }
  },
  "main": "dist/index.cjs.js",
  "module": "dist/index.es.js",

Your Example Website or App

https://stackblitz.com/edit/vitejs-vite-bwqota?file=src%2FApp.tsx

Steps to Reproduce the Bug or Issue

  1. Go to Stackblitz above
  2. Observe the error in App.tsx

Expected behavior

Should not get a TS error.

Screenshots or Videos

No response

Platform

macOS, but presumably all.

Additional context

No response

samesfahani-tuplehealth avatar Apr 15 '24 21:04 samesfahani-tuplehealth