typedoc: TypeError: Cannot read property 'flags' of undefined

I got this error during the execution of typedoc:


 return !!(type.flags & 80896);
                      ^
TypeError: Cannot read property 'flags' of undefined
    at ReferenceConverter.supportsNode ([....]node_modules\typedoc\lib\converter\types\reference.js:26:23)
    at Converter.convertType ([....]node_modules\typedoc\lib\converter\converter.js:127:31)
    at [....]node_modules\typedoc\lib\converter\nodes\class.js:47:63
    at Context.withScope ([....]node_modules\typedoc\lib\converter\context.js:99:9)
    at ClassConverter.convert ([....]node_modules\typedoc\lib\converter\nodes\class.js:35:17)
    at Converter.convertNode ([....]node_modules\typedoc\lib\converter\converter.js:117:53)
    at [....]node_modules\typedoc\lib\converter\nodes\block.js:71:33
    at Array.forEach (native)
    at BlockConverter.convertStatements ([....]node_modules\typedoc\lib\converter\nodes\block.js:69:29)
    at [....]node_modules\typedoc\lib\converter\nodes\block.js:55:27

Does someone has an idea what the problem could be?

Typedoc v. 0.4.1 Tpyescript v.1.18.10

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 8
  • Comments: 26

Commits related to this issue

Most upvoted comments

Have the same issue (node v6.9.1)

> typedoc --out docs ./

Using TypeScript 2.0.6 from C:\Users\dima\AppData\Roaming\npm\node_modules\typedoc\node_modules\typescript\lib
C:\Users\dima\AppData\Roaming\npm\node_modules\typedoc\lib\converter\types\reference.js:26
        return !!(type.flags & ts.TypeFlags.ObjectType);
                      ^

TypeError: Cannot read property 'flags' of undefined
    at ReferenceConverter.supportsNode (C:\Users\dima\AppData\Roaming\npm\node_modules\typedoc\lib\converter\types\reference.js:26:23)
    at Converter.convertType (C:\Users\dima\AppData\Roaming\npm\node_modules\typedoc\lib\converter\converter.js:129:31)
    at C:\Users\dima\AppData\Roaming\npm\node_modules\typedoc\lib\converter\nodes\class.js:52:63
    at Context.withScope (C:\Users\dima\AppData\Roaming\npm\node_modules\typedoc\lib\converter\context.js:98:9)
    at ClassConverter.convert (C:\Users\dima\AppData\Roaming\npm\node_modules\typedoc\lib\converter\nodes\class.js:36:17)
    at Converter.convertNode (C:\Users\dima\AppData\Roaming\npm\node_modules\typedoc\lib\converter\converter.js:119:53)
    at C:\Users\dima\AppData\Roaming\npm\node_modules\typedoc\lib\converter\nodes\block.js:71:33
    at Array.forEach (native)
    at BlockConverter.convertStatements (C:\Users\dima\AppData\Roaming\npm\node_modules\typedoc\lib\converter\nodes\block.js:69:29)
    at C:\Users\dima\AppData\Roaming\npm\node_modules\typedoc\lib\converter\nodes\block.js:55:27

I ran into this issue when I wasn’t compiling something outside of my source directory. My tsconfig had

files [‘all.ts’ (from ./src), ‘…/typings/index.d.ts’]

but I was only running

typedoc --out ./doc ./src

The solution was to run

typedoc --out ./doc ./src ./typings/index.d.ts

The root cause is that it’s a configuration issue, but it’s a code issue in that the error thrown is unhelpful.

I’m using TypeScript 2.0.6 and am getting this error. --excludeExternals did not resolve the issue.

yarn run v0.16.1
$ typedoc --out ./docs ./src --excludeExternals

Using TypeScript 2.0.6 from C:\[...]\node_modules\typescript\lib
C:\[...]\node_modules\typedoc\lib\converter\types\reference.js:26
        return !!(type.flags & ts.TypeFlags.ObjectType);
                      ^

TypeError: Cannot read property 'flags' of undefined
    at ReferenceConverter.supportsNode (C:\[...]\node_modules\typedoc\lib\converter\types\reference.js:26:23)
    at Converter.convertType (C:\[...]\node_modules\typedoc\lib\converter\converter.js:129:31)
    at C:\[...]\node_modules\typedoc\lib\converter\nodes\class.js:52:63
    at Context.withScope (C:\[...]\node_modules\typedoc\lib\converter\context.js:98:9)
    at ClassConverter.convert (C:\[...]\node_modules\typedoc\lib\converter\nodes\class.js:36:17)
    at Converter.convertNode (C:\[...]\node_modules\typedoc\lib\converter\converter.js:119:53)
    at C:\[...]\node_modules\typedoc\lib\converter\nodes\block.js:71:33
    at Array.forEach (native)
    at BlockConverter.convertStatements (C:\[...]\node_modules\typedoc\lib\converter\nodes\block.js:69:29)
    at C:\[...]\node_modules\typedoc\lib\converter\nodes\block.js:55:27
error Command failed with exit code 1.

Experienced the same issue, --excludeExternals didn’t work for me.

We had to use --moduleResolution node

Edit: Using TypeScript 1.8.10

I was having the same issue, while using the typedoc api to generate the docs. Firstly, I overrode the supportsNode functions to stop the Cannot read property 'flags' of undefined error (thanks @mashaalmemon for the idea):

var typedocConverterTypes = require("typedoc/lib/converter/types");
typedocConverterTypes.ReferenceConverter.prototype.supportsNode = function(context, node, type) {
    return !!(type && (type.flags & ts.TypeFlags.ObjectType));
}
typedocConverterTypes.TypeParameterConverter.prototype.supportsNode = function(context, node, type) {
    return !!(type && (type.flags & ts.TypeFlags.TypeParameter));
}

Note that those are the only two type converters that attempt to access type.flags, so this should cover all cases.

After that, the undefined error went away, but I got a lot of module errors. This was because my code required moduleResolution to be classic, but hadn’t configured that in my typedoc code. I enabled this using the code:

var ts = require("typescript");
var app = new typedoc.Application({
    readme: "help-index.markdown",
    name: "My Website",
    excludeExternals: false
});

app.options.getCompilerOptions().moduleResolution = ts.ModuleResolutionKind.Classic;
// ... more config

After that, typedoc ran successfully. I could also then remove the hack above, and it would still succeed.

This seems to indicate the Cannot read property 'flags' of undefined error is hiding other more appropriate errors, making the initial hack fix possibly a good idea. Also, it appears to be cause by multiple config errors (e.g. it had nothing to do with excludeExternals for me while that fixed the problem for other people).

Here is the full code I’m using to generate my docs:

var typedoc = require('typedoc');
var ts = require("typescript");

// hack: fix the "Cannot read property 'flags' of undefined" error. I don't actually require this, 
// but it doesn't break anything by leaving it in
var typedocConverterTypes = require("typedoc/lib/converter/types");
typedocConverterTypes.ReferenceConverter.prototype.supportsNode = function(context, node, type) {
    return !!(type && (type.flags & ts.TypeFlags.ObjectType));
}
typedocConverterTypes.TypeParameterConverter.prototype.supportsNode = function(context, node, type) {
    return !!(type && (type.flags & ts.TypeFlags.TypeParameter));
}
// end of hack

function generateDocs() {
    var app = new typedoc.Application({
        readme: "help-index.markdown",
        name: "My Website",
        mode: "modules", // either "file" or "modules"
        excludeExternals: false
    });
    app.options.getCompilerOptions().module = "commonjs";
    app.options.getCompilerOptions().moduleResolution = ts.ModuleResolutionKind.Classic;
    app.options.getCompilerOptions().target = "es5";
    app.options.getCompilerOptions().experimentalDecorators = true;

    var files = app.expandInputFiles(["src/", "typings/tsd.d.ts"]);
    //console.log(files);
    app.generateDocs(files, "docs");

}

module.exports = {
    generateDocs: generateDocs
};

@aciccarello Was working on a PR and realized that after some changes in my typedoc setup that I was no longer able to replicate the error condition. The current 0.4.4 release was working. Digging deeper, realized that this may be simply a configuration problem and not a code problem.

I was experiencing this error when typedoc was trying to document “external” libraries (libraries external to my project as I understand it). Thus the issue may have been related to referenced typescript and not your own.

Whoever is experiencing this, try to set the “–excludeExternals” flag:

typedoc --excludeExternals

OR if using “gulp-typedoc” like me, set “excludeExternals:true”:

return gulp
        .src(["*"])
        .pipe(typedoc({
            ...
            excludeExternals: true
            ...
        }))

Thus no PR may be necessary for this issue. Can some of the folks in here try this and advise? @samvv @kylenicola @ajayambre

If so, maybe “excludeExternals” should be set to “true” as a default. I don’t see why external libraries should be documented by default?

@aciccarello My work around was a bit “hacky” and satisfied my need. Ultimately a variable that is expected to be set is not yet set when encountered, and so typedoc fails.

I’ll aim to PR a similar but better tested fix when I get a chance ASAP as a starting point for the maintainers (with a better wholistic understanding of the codebase) to use as a starting point. Stay tuned.

Facing same issue when using gulp-type