賞金將在 5 天后到期。此問題的答案有資格獲得 100聲望賞金。 Sam Stern想引起更多人對這個問題的關注。
我有一個具有以下配置的 TS 專案:
tsconfig.json(部分)
{
"compilerOptions": {
"module": "commonjs",
"baseUrl": "src",
"esModuleInterop": true,
},
"include": [
"src"
]
}
我依賴于stripeNPM 包:
{
// ...
"dependencies": {
"stripe": "^8.45.0",
}
}
然后我有以下檔案:
src/routes/payments/index.ts
src/stripe/index.ts
我在匯入時遇到了一些麻煩src/routes/payments/index.ts。我想匯入stripe庫,而不是我自己的代碼。
這有效:
// Uses me the 'Stripe' constructor which is the default export from the package
const stripe = require('stripe')('KEY');
這不起作用:
import Stripe from 'stripe';
const stripe = new Stripe('KEY');
我收到以下錯誤:
Module '"PROJECT/src/stripe/index"' has no default export.
如何消除歧義并告訴 TS 我想stripe從 node_modules 使用?
uj5u.com熱心網友回復:
您可以嘗試像這樣更新tsconfig.json檔案嗎:
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/*"
]
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/442290.html
標籤:javascript 节点.js 打字稿 npm 条纹支付
