[英]How to make Typescript detect import path error with a case sensitive typo?
Typescript didn't detect this typo error (case sensitive). Typescript 没有检测到这个拼写错误(区分大小写)。
The name of the file: AdminTextArea
文件名:
AdminTextArea
The import with the typo import AdminTextArea from "@components/AdminTextarea"
导入错误
import AdminTextArea from "@components/AdminTextarea"
The typo is: area
instead of the correct word Area
.拼写错误是:
area
而不是正确的单词Area
。
My Typescript environment didn't complain about this at all.我的 Typescript 环境根本没有抱怨这个。
No errors are shown and it runs smoothly.没有显示错误并且运行顺利。
It was only after I've transpiled it to JS with babel and sent it to run on my Docker container on the cloud, that it triggered this error:只有在我用 babel 将它转译为 JS 并将其发送到云上我的 Docker 容器上运行之后,它才触发了这个错误:
The path is perfect, except for the typo.路径是完美的,除了错别字。
What can I do to detect this error in my dev Typescript environment?我该怎么做才能在我的 dev Typescript 环境中检测到此错误? Is this an
eslint
thing or is my Typescript not configured correctly?这是
eslint
还是我的 Typescript 配置不正确?
This is operating-system dependent.这取决于操作系统。 Some operating systems have a case-insensitive file system (MacOS would be the primary example).
某些操作系统具有不区分大小写的文件系统(MacOS 将是主要示例)。 Linux file systems are case-sensitive, so this error may manifest when moving from a case-insensitive file system to one that is case-sensitive.
Linux 文件系统区分大小写,因此当从不区分大小写的文件系统移动到区分大小写的文件系统时,可能会出现此错误。
Unfortunately, TypeScript can't do much about this since it depends on the file system itself.不幸的是,TypeScript 对此无能为力,因为它取决于文件系统本身。 You can add this compiler setting:
您可以添加此编译器设置:
{
"compilerOptions": {
"forceConsistentCasingInFileNames": true
This may help detect this error.这可能有助于检测此错误。
With ESLint rule import/no-unresolved you can make sure that case sensitive imports are added correctly.使用 ESLint 规则import/no-unresolved ,您可以确保正确添加区分大小写的导入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.