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

Could not find a declaration file for module #93

Closed bryanjhickey closed 3 months ago

bryanjhickey commented 10 months ago

Describe the bug

Getting typescript error.

Could not find a declaration file for module 'react-square-web-payments-sdk'. '/PATH/.pnpm/react-square-web-payments-sdk@3.2.1_react@18.2.0/node_modules/react-square-web-payments-sdk/dist/index.es.js' implicitly has an 'any' type.
  There are types at '/PATH/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.

Your Example Website or App

https://github.com/bjh-dev/bjh-dev-shop/tree/square-payments

Steps to Reproduce the Bug or Issue

My next.config.js is

/** @type {import('next').NextConfig} */
const nextConfig = {
  transpilePackages: ['@/square/web-sdk', 'react-square-web-payments-sdk'],
  experimental: {
    esmExternals: 'loose',
  },
}

module.exports = nextConfig

I have a component

'use client'

import * as React from 'react'
import {
  ApplePay,
  CreditCard,
  GooglePay,
  PaymentForm,
} from 'react-square-web-payments-sdk'

function OrderForm() {
  return (
    <div>
      <PaymentForm
        applicationId={process.env.NEXT_PUBLIC_SQUARE_APP_ID}
        locationId={process.env.NEXT_PUBLIC_SQUARE_LOCATION_ID}
        createPaymentRequest={() => ({
          countryCode: 'AU',
          currencyCode: 'AUD',
          requestBillingContact: false,
          requestShippingContact: false,
          total: {
            amount: '41.79',
            label: 'Total',
          },
        })}
      >
        <ApplePay />
        <GooglePay />
        <CreditCard includeInputLabels />
      </PaymentForm>
    </div>
  )
}

export default OrderForm

Which results in the following typescript error

Could not find a declaration file for module 'react-square-web-payments-sdk'. '/PATH/.pnpm/react-square-web-payments-sdk@3.2.1_react@18.2.0/node_modules/react-square-web-payments-sdk/dist/index.es.js' implicitly has an 'any' type.
  There are types at '/PATH/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.

Expected behavior

Expected package to find its own types when imported

Screenshots or Videos

No response

Platform

Next 13.4.16 Node 18.17.0 Typescript 5.1.6

Additional context

None

carwin commented 8 months ago

Adding "noImplicitAny": false to the compilerOptions gets around this, but it isn't ideal.

baberMatt commented 7 months ago

Any update on this? Running into same error but using Remix? Tried tweaking import statement and moduleResolution in tsconfig as well as declaring types locally and nothing seems to resolve it?

carterchris43 commented 6 months ago

also interested if there's any update on this

mrfzd commented 5 months ago

noImplicitAny

Thanks for this but it's surprising this is not fixed yet!

easydoesit commented 4 months ago

I'm getting the same error. Is there a fix coming or can anybody suggest how to fix this?

raycoga commented 3 months ago

i have the same issue using react 18 with typescript