microsoft / microsoft/TypeScript

"Cannot find module" message should be more explicit, saying where it's looking

未关闭
#5,149 11 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

Help Wanted Suggestion
主要语言
Go
星标
111k
派生
14.3k
平均合并
2 天 4 小时
30 天内合并 PR
132

描述

With all the vagaries around module loading, it'd be great to give a more verbose, helpful error message for "Cannot find module 'foo'", saying where the compiler looked for the module. That can help clue the user into (1) how TypeScript works and (2) how to fix their issue.

The message text could be semi-static, maybe something like: IF using commonjs loading AND path isn't relative THEN say "Couldn't find module Foo; searched node_modules directory off directory XXXX and its ancestors and the package.json Typings path YYYY.

Better doc around the module loading algorithm helps, but just putting some of that info in the error message makes it very easily discovered. It also helps clue the user into what isn't the problem (e.g. the message above confirms that using commonjs module loading & found Typings in package.json, but something else seems to be the problem).

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先阅读 issue 中关于 CommonJS 模块加载、祖先目录中的 node_modules 搜索以及 package.json 中 Typings 路径的描述。跟踪编译器的模块解析和诊断入口点,然后找出现有的 "Cannot find module" 错误测试。完成的标准是:诊断信息说明了解析搜索过的位置,同时不掩盖原始失败原因。

由索引模型根据 Issue 内容生成。

评估

技术栈
typescript
领域
compilers
Issue 类型
功能
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。