【问题标题】:TypeDoc can not find Angular2 modulesTypeDoc 找不到 Angular2 模块
【发布时间】:2016-05-03 03:26:17
【问题描述】:

我正在尝试使用 TypeDoc 生成 doc 文件。当我使用以下命令运行 TypeDoc 时:

/node_modules/.bin/typedoc --module system --target ES5 --exclude *.spec.ts* --experimentalDecorators --out typedoc app/ --ignoreCompilerErrors

它作为输出给出:

Using TypeScript 1.6.2 from /development/node_modules/typedoc/node_modules/typescript/lib
Error: /development/app/angular2/app.ts(1)
 Cannot find module 'angular2/core'.
Error: /development/app/angular2/app.ts(2)
 Cannot find module 'angular2/upgrade'.
Error: /development/app/angular2/app.ts(3)
 Cannot find module 'angular2/platform/browser'.
Error: /development/app/angular2/app.ts(5)

tsconfig.json

{
  "compilerOptions": {
    "target": "ES5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules"
  ]
}

这里是否缺少某种参数来包含库或.d.ts. 文件?

【问题讨论】:

  • 可能是一些与 tsconfig.json 相关的问题。可以发一下吗?
  • 我已将我的 tsconfig,json 添加到问题中

标签: angular typescript typedoc


【解决方案1】:

我将 typedoc 与 angular2 应用程序一起使用。虽然我通过 gulp-typedoc 运行它,但传递的参数应该是相同的。以下 gulp 任务为我完成了这项工作:

gulp.task("doc", function() {
    return gulp
        .src(["./myproject/**/*.ts"])
        .pipe(typedoc({ 
            // TypeScript options (see typescript docs) 
            module: "commonjs", 
            target: "es5",
            includeDeclarations: false,
            experimentalDecorators: true,

            // Output options (see typedoc docs) 
            out: "./docs", 

            // TypeDoc options (see typedoc docs) 
            name: "MyProject", 
            ignoreCompilerErrors: false,
            excludeExternals:true,
            version: true,
        }));
});

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    我尝试了 commonjs 模块,它成功了。

    typedoc --experimentalDecorators --target 'es5' --module 'commonjs' --out doc-destination/ src/
    

    【讨论】:

      【解决方案3】:

      在您的 tsconfig.json 中添加类型定义文件的配置并尝试

      "typeRoots": [
        "node_modules/@types" ]
      

      【讨论】:

        猜你喜欢
        • 2016-07-08
        • 1970-01-01
        • 2016-04-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-09-15
        • 2016-09-25
        • 1970-01-01
        相关资源
        最近更新 更多