简体   繁体   中英

Stripe is not declared

I'm trying to import stripe:

import Stripe from "stripe"

It should work but I'm getting this error:

Could not find a declaration file for module 'stripe'. 'server/node_modules/stripe/lib/stripe.js' implicitly has an 'any' type.

I tried to install @types/stripe but it didn't help and they are deprecated:

This is a stub types definition. stripe provides its own type definitions, so you do not need this installed.

This is the package.json file:

{
    "version": "1.0.0",
    "main": "index.js",
    "license": "ISC",
    "scripts": {},
    "dependencies": {
        "stripe": "^11.8.0",
        "typescript": "^4.9.4"
    },
    "devDependencies": {
        ...
    }
}

I don't have type: "module" and @types/stripe .

This is the tsconfig.json :

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
  },
  "exclude": [
    "node_modules",
    "web/node_modules",
  ]
}

If I download stripe version ^10.17.0 everything works, so the problem is probably in stripe version ^11.8.0 .

Node.js doesn't support ES6 import directly. You need to add "type":"module" in your package.json file to enables ES6 module support.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM