Sam*_*ern 5 javascript node.js npm stripe-payments typescript
我有一个 TS 项目,配置如下:
tsconfig.json(部分)
{
"compilerOptions": {
"module": "commonjs",
"baseUrl": "src",
"esModuleInterop": true,
},
"include": [
"src"
]
}
Run Code Online (Sandbox Code Playgroud)
我对 NPM 包有依赖stripe
:
{
// ...
"dependencies": {
"stripe": "^8.45.0",
}
}
Run Code Online (Sandbox Code Playgroud)
然后我有以下文件:
src/routes/payments/index.ts
src/stripe/index.ts
Run Code Online (Sandbox Code Playgroud)
我在导入时遇到一些问题src/routes/payments/index.ts
。我想导入stripe
库,而不是我自己的代码。
这有效:
// Uses me the 'Stripe' constructor which is the default export from the package
const stripe = require('stripe')('KEY');
Run Code Online (Sandbox Code Playgroud)
这不起作用:
import Stripe from 'stripe';
const stripe = new Stripe('KEY');
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Module '"PROJECT/src/stripe/index"' has no default export.
Run Code Online (Sandbox Code Playgroud)
如何消除歧义并告诉 TS 我想stripe
从 node_modules 使用?
您可以尝试像这样更新tsconfig.json文件吗:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/*"
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
773 次 |
最近记录: |