[英]Imports from public folder Nextjs in typescript give error: Cannot find module
I am trying to import files using regular import and with the custom absolute paths in Nextjs using typescript.我正在尝试使用常规导入和 Nextjs 中使用 typescript 的自定义绝对路径导入文件。 For some reason I keep getting an error that the module cannot be found but my IDE is able to link the file when I click on it.
出于某种原因,我不断收到一个错误,提示找不到该模块,但我的 IDE 在我单击它时能够链接该文件。 Also, when its a regular javascript file, instead of typescript, it works fine and files are imported.
此外,当它是一个常规的 javascript 文件而不是打字稿时,它可以正常工作并导入文件。
For now im using // @ts-ignore and it works, but I wonder if there is a better way to solve this error.现在我使用 // @ts-ignore 并且它有效,但我想知道是否有更好的方法来解决这个错误。
My tsconfig:我的 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"
]
}
Try changing the path of the import.尝试更改导入路径。
If you have a baseUrl
of “.”
如果您的
baseUrl
为“.”
, the path would be ...from '/public/...'
. ,路径将是
...from '/public/...'
。 instead of ...from './public/...'
而不是
...from './public/...'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.