【发布时间】:2021-11-16 03:32:40
【问题描述】:
我正在尝试使用常规导入和 Nextjs 中使用 typescript 的自定义绝对路径来导入文件。 由于某种原因,我不断收到无法找到模块的错误消息,但是当我单击它时,我的 IDE 能够链接该文件。此外,当它是一个常规的 javascript 文件而不是 typescript 时,它可以正常工作并导入文件。
现在我使用 //@ts-ignore 并且它可以工作,但我想知道是否有更好的方法来解决这个错误。
我的 tsconfig:
{
"compilerOptions": {
"target": "es2015",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"baseUrl": ".",
"paths": {
"@/*": ["src/components/*"],
"#/*": ["public/assets/images/*"],
}
},
"include": [
"public/**/*",
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}
【问题讨论】:
-
尝试从 tsconfig 中删除
baseUrl和paths
标签: javascript reactjs typescript ecmascript-6 next.js