IntelliJ Ultimate遇NoSuchElementException,疑与TypeScript相关求助
解决IntelliJ Ultimate中
java.util.NoSuchElementException: List is empty异常 从错误栈能明确,这个异常是IntelliJ的React客户端组件高亮策略在处理JSX自定义标签时触发的——IDE内部调用Kotlin的first()方法时目标列表为空,属于IDE代码解析/高亮模块的问题,和业务代码逻辑无关,大概率和TypeScript/JSX的IDE插件解析逻辑相关。
以下是具体解决思路:
- 强制刷新IDE缓存:打开
File菜单选择Invalidate Caches...,勾选Invalidate and Restart选项后重启IDE,这是解决多数IDE索引、高亮类问题的通用方案。 - 检查插件版本:进入
Settings -> Plugins,找到JavaScript and TypeScript、React官方插件,确认是否为最新稳定版;如果是更新插件后出现的问题,可以尝试回退到上一个版本。 - 排查异常JSX结构:检查项目中是否存在格式异常的自定义JSX标签,比如未闭合标签、属性语法错误、未正确导入的组件等,这类异常结构可能导致IDE解析逻辑崩溃。
- 禁用第三方插件:如果安装了第三方的TypeScript/JSX高亮、语法检查插件,暂时禁用后重启IDE,排查是否是插件冲突导致。
- 重新导入项目:将项目从IDE中移除,然后重新导入,避免项目配置文件损坏引发的解析异常。
完整错误栈
java.util.NoSuchElementException: List is empty. at kotlin.collections.CollectionsKt___CollectionsKt.first(_Collections.kt:214) at kotlin.collections.CollectionsKt___CollectionsKt.first(_Collections.kt:197) at com.intellij.lang.javascript.frameworks.jsx.ReactClientComponentHighlightingStrategy.highlightCustomTag(ReactClientComponentHighlightingStrategy.kt:44) at com.intellij.xml.XmlCustomTagHighlightingPass.getCustomAttributeKey(XmlCustomTagHighlightingPass.kt:115) at com.intellij.xml.XmlCustomTagHighlightingPass.replaceTextAttributeKeys(XmlCustomTagHighlightingPass.kt:87) at com.intellij.xml.XmlCustomTagHighlightingPass.applyHighlighting(XmlCustomTagHighlightingPass.kt:78) at com.intellij.xml.XmlCustomTagHighlightingPass.access$applyHighlighting(XmlCustomTagHighlightingPass.kt:40) at com.intellij.xml.XmlCustomTagHighlightingPass$doCollectInformation$1.visitXmlTag(XmlCustomTagHighlightingPass.kt:59) at com.intellij.psi.impl.source.xml.XmlTagImpl.accept(XmlTagImpl.java:268) at com.intellij.lang.javascript.psi.e4x.impl.JSXmlLiteralExpressionImpl.accept(JSXmlLiteralExpressionImpl.java:43) at com.intellij.psi.PsiWalkingState.visit(PsiWalkingState.java:53) at com.intellij.psi.PsiWalkingState.visit(PsiWalkingState.java:10) at com.intellij.util.WalkingState.walkChildren(WalkingState.java:65) at com.intellij.util.WalkingState.elementStarted(WalkingState.java:42) at com.intellij.psi.PsiWalkingState.elementStarted(PsiWalkingState.java:62) at com.intellij.psi.XmlRecursiveElementWalkingVisitor.visitElement(XmlRecursiveElementWalkingVisitor.java:40) at com.intellij.lang.javascript.psi.impl.JSVarStatementBase.accept(JSVarStatementBase.java:49) at com.intellij.psi.impl.source.tree.SharedImplUtil.acceptChildren(SharedImplUtil.java:183) at com.intellij.psi.impl.source.PsiFileImpl.acceptChildren(PsiFileImpl.java:748) at com.intellij.xml.XmlCustomTagHighlightingPass.doCollectInformation(XmlCustomTagHighlightingPass.kt:46) at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:55) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$1(PassExecutorService.java:406) at com.intellij.platform.diagnostic.telemetry.helpers.TraceKt.runWithSpanIgnoreThrows(trace.kt:76) at com.intellij.platform.diagnostic.telemetry.helpers.TraceUtil.runWithSpanThrows(TraceUtil.java:34) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:401) at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1075) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$3(PassExecutorService.java:392) at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$12(CoreProgressManager.java:610) at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:685) at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:641) at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:609) at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:78) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:391) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:367) at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:200) at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:184) at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:365) at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:187) at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373) at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182) at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655) at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622) at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
内容的提问来源于stack exchange,提问作者Etienne Herlaut
相关产品推荐
相关产品推荐

