TypeScript错误:在undefined(undefined,undefined)中。

6
我遇到了 TypeScript 错误:
```text ```
Failed to compile.

undefined
TypeScript error in undefined(undefined,undefined):
File name '/path/to/file/MyFileName.types.tsx' differs from already included file name '/path/to/file/myFileName.types.tsx' only in casing.  TS1149

注意 myFileNameMyFileName 的首字母区别。我不知道为什么会出现这种情况,也不知道该如何解决。我以前从没见过这种错误。 我使用的是 TypeScript 版本 3.5.3。如果有人能至少指点我应该怎么做,那就太有帮助了。


为了解决类似的问题,我不得不执行rm -rf node_modules,然后再次运行yarn install。不太确定问题出在哪里。 - Eliezer Steinbock
4个回答

5

针对我的情况,我只需使用以下命令安装包:

npm i


(备注:此处“i”是install的缩写)

3

糟糕,我的代码中有一个小写字母导入:

import { TSomething } from './myFileName.types'

实际的文件名字是大写的:

MyFileName.types.tsx

我仍然不知道为什么TypeScript编译器没有告诉我那个地方在哪里。


2

只需要运行:
“yarn tsc” 或者 npm。 就可以了!


0

好的,这可能是我见过的最疯狂的错误了。

上下文

  • vue 2.6.10
  • typescript 4.4.3
  • 使用vue-cli-service build通过webpack构建。

我在构建时遇到了以下错误:

⠼  Building for production...

 ERROR  Failed to compile with 1 errors                                                                                                   10:49:11

 error  in [internal]

INTERNAL ERROR(undefined,undefined) Debug Failure.
stack trace:
Error: Debug Failure.
    at /Users/user/path/to/repo/node_modules/typescript/lib/typescript.js:19487:89
    at String.replace (<anonymous>)
    at formatStringFromArgs (/Users/user/path/to/repo/node_modules/typescript/lib/typescript.js:19487:21)
    at Object.createDetachedDiagnostic (/Users/user/path/to/repo/node_modules/typescript/lib/typescript.js:19503:20)
    at parseErrorAtPosition (/Users/user/path/to/repo/node_modules/typescript/lib/typescript.js:30898:42)
    at parseErrorAt (/Users/user/path/to/repo/node_modules/typescript/lib/typescript.js:30905:13)
    at parseErrorAtCurrentToken (/Users/user/path/to/repo/node_modules/typescript/lib/typescript.js:30892:13)
    at parseErrorForInvalidName (/Users/user/path/to/repo/node_modules/typescript/lib/typescript.js:31130:17)
    at parseErrorForMissingSemicolonAfter (/Users/user/path/to/repo/node_modules/typescript/lib/typescript.js:31102:21)
    at parseExpressionOrLabeledStatement (/Users/user/path/to/repo/node_modules/typescript/lib/typescript.js:34993:21)

 ERROR  Build failed with errors.

解决方案

错误是在Vue模板中出现了一个HTML文本

<template>
  ...
  Please type "{{ listName }}" to confirm.
  ...
</template>

我不得不用其他词来替换type以修复TypeScript错误:

请写入 "{{ listName }}" 以确认。

更新

经过进一步的实验,导致问题的原因是HTML文本中的以下模式:

type "

双引号之间可以放置任何内容,因此type ""type "hello"等都会导致此错误。

相反,当我在type"之间放置任何内容时,它会再次构建,例如type a "


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接