未定义的 TypeScript 错误(未定义,未定义)

TypeScript error in undefined(undefined,undefined)

我遇到了 TypeScript 错误:

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。如果有人至少可以指出我该怎么做,那将非常有帮助。

哦废话。我的代码中某处有一个小写的导入:

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

而真实文件名是大写的:

MyFileName.types.tsx

我仍然不知道为什么 TypeScript 编译器不告诉我它在哪里。

就我而言,我只是使用此命令安装了软件包

npm i

就运行:
"yarn tsc" 或 npm。 有效!

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

上下文

  • vue 2.6.10
  • 打字稿 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 错误:

请<b>写</b>“{{ listName }}”确认。

更新

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

type "

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

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