weareseeed / react-square-web-payments-sdk

Easily create PCI-compliant inputs to accept payments online with the Square Payments API. It supports the following payment methods: credit and debit cards, ACH bank transfers, Apple Pay, Google Pay, Gift Cards and Afterpay/Clearpay.
https://react-square-payments.weareseeed.com/
MIT License
33 stars 35 forks source link

Typing with CJS and ESM interop are still incompatible #107

Open samesfahani-tuplehealth opened 2 months ago

samesfahani-tuplehealth commented 2 months ago

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

sludemann commented 2 months ago

I'm also encountering the same issue with latest.

dir commented 1 week ago

Getting the same issue here

miurhawk commented 6 days ago

package.json needs to be updated:

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

  someone has made an attempt at doing this in the master branch but the result hasn't built to a release