导入时baseUrl和node_modules之间存在冲突



我有一个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我想从node_modules使用stripe

你能尝试像这样更新tsconfig.json文件吗:

{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"baseUrl": ".",
"paths": {
"*": [
"node_modules/*",
"src/*"
]
}
}
}

最新更新