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

Created on 7 Jun 2016  路  26Comments  路  Source: TypeStrong/typedoc

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

bug help wanted

Most helpful comment

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

All 26 comments

Facing same issue when using gulp-type

Please take a look at #223 and / or #224

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

I saw the same thing once. The best you can do is, to use a tsconfig file for compiling and for typedoc. Seems, that typedoc invokes something that fails without catching the error. When this error occured, i ran tsc and it failed, too. Best is, to get compilation pass before generating typedoc.

I'm having the same issue when invoking TypeDoc programmatically. Anyone knows how to fix this? tsconfig.json is in my case not an option because I need to dynamically render the documentation.

TypeDoc 0.4.4

const documenter = new TypeDoc.Application({
   mode: 'file'
})

documenter.generateDocs(['index.d.ts'], 'cache/typedoc/test'))
Using TypeScript 1.8.10 from /Users/samvv/Projects/websites/typings/api/node_modules/typescript/lib
TypeError: Cannot read property 'flags' of undefined
    at ReferenceConverter.supportsNode (/Users/samvv/Projects/websites/typings/api/node_modules/typedoc/lib/converter/types/reference.js:26:23)
    at Converter.convertType (/Users/samvv/Projects/websites/typings/api/node_modules/typedoc/lib/converter/converter.js:127:31)
    at /Users/samvv/Projects/websites/typings/api/node_modules/typedoc/lib/converter/nodes/class.js:47:63
    at Context.withScope (/Users/samvv/Projects/websites/typings/api/node_modules/typedoc/lib/converter/context.js:99:9)
    at ClassConverter.convert (/Users/samvv/Projects/websites/typings/api/node_modules/typedoc/lib/converter/nodes/class.js:35:17)
    at Converter.convertNode (/Users/samvv/Projects/websites/typings/api/node_modules/typedoc/lib/converter/converter.js:117:53)
    at /Users/samvv/Projects/websites/typings/api/node_modules/typedoc/lib/converter/nodes/block.js:71:33
    at Array.forEach (native)
    at BlockConverter.convertStatements (/Users/samvv/Projects/websites/typings/api/node_modules/typedoc/lib/converter/nodes/block.js:69:29)
    at /Users/samvv/Projects/websites/typings/api/node_modules/typedoc/lib/converter/nodes/block.js:55:27

I saw the same issue when typescript@next was installed; using typescript 1.8.10, typedoc complained about 'Cannot find name/module/...'.
In both cases the project transpiled successfully by tsc!
The workaround mentioned by kylenicola worked for me.

I am experiencing the same issue. Workaround from "kylenicola" couldn't be actioned. I am not using "files" property in my tsconfig.json - rather I am using the "exclude".

Instead, without digging too deep into the source code, I simply went into the source where "types.flag" was being read in "reference.js" and again in "type-parameter.js" and set "type" to an empty object just before it was accessed ("type = {}"). My docs are now being emitted without issue.

Not sure if the underlying issue has been diagnosed and a fix is pending?

@mashaalmemon I don't think anyone has been working on this. I'm sure a PR would be appreciated.

@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.

That'd be great! The project has switched maintainers so I'm not sure anyone has a holistic understanding of the codebase at this point :smile: But a PR allow someone to dig a little deeper so I'd say go for it.

@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?

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

I don't see why external libraries should be documented by default?

You're right, I'm thinking the same thing. Will try it out when I find the time.

Same issue, --excludeExternals didn't work for me.

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
};

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

We had to use --moduleResolution node

Edit: Using TypeScript 1.8.10

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.

I was having the same issue, TypeScript 2.0.6, resolved by ensuring all the d.ts dependencies were included in the typedoc src

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

just want to share that I use '--includeDeclarations' to solve this error

My Project is Angular 2 with Angular-Cli/Webpack
I found that you can find out some setting hints from tsconfig.json
And follow the webpack plugin ( https://www.npmjs.com/package/typedoc-webpack-plugin ) default options can be a good starting point

ps. but I am now facing 'process out out memory' error

I have had the same problem, and the root cause was a TypeScript (tsc) compile error. Regardless of my ignoreCompilerErrors setting (true or false), I would get the error. Correcting my source code to compile without error solved my problem.

Posting in case this helps someone else.

Same problem here.

Using:

  • TypeScript 2.0.6
  • Ionic 2.0.0 RC4
  • Ubuntu 16.04

Tried using this options without luck (error message was always equal to the one below):

  • --includeDeclarations
  • --excludeExternals
  • --moduleResolution node

The project can be compiled and the resulting app runs without problems on my SmartPhone

$ typedoc --out doc/ src/

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

TypeError: Cannot read property 'flags' of null
    at ReferenceConverter.supportsNode (/usr/lib/node_modules/typedoc/lib/converter/types/reference.js:26:23)
    at Converter.convertType (/usr/lib/node_modules/typedoc/lib/converter/converter.js:129:31)
    at /usr/lib/node_modules/typedoc/lib/converter/types/binding-array.js:28:36
    at Array.forEach (native)
    at BindingArrayConverter.convertNode (/usr/lib/node_modules/typedoc/lib/converter/types/binding-array.js:27:23)
    at Converter.convertType (/usr/lib/node_modules/typedoc/lib/converter/converter.js:130:38)
    at /usr/lib/node_modules/typedoc/lib/converter/factories/parameter.js:15:48
    at Context.withScope (/usr/lib/node_modules/typedoc/lib/converter/context.js:98:9)
    at Object.createParameter (/usr/lib/node_modules/typedoc/lib/converter/factories/parameter.js:13:13)
    at /usr/lib/node_modules/typedoc/lib/converter/factories/signature.js:16:25

How can ensure, I added all index.d.ts? My tsconfig.json doesn't contain any references to .d.ts files.

Seeing this too. Any progress? Anyone know why switching out of my IDE causes the HMR to reload the entire page? That is when I get this error, restarting angular-cli ng serve and the error goes away.

get someData () {
  return this._someData
}
....
someFunc () {
  const { someData } = this
  // Above line occured error -> TypeError: Cannot read property 'flags' of undefined
  // and will ignore some lint warning like "never used", "semicolon" in this ts file 
  // fuck this bug. 
}

Watching with webpack has never worked for me. It doesn't read file changes and when it should, this error appears.

Closing as it seems this has been fixed. 0.4.x is a really old version of TypeDoc, and with strict null checks on, TypeScript should now give an error if something is missed that causes an error like this. I tried running TypeDoc on hiyali's code and generated documentation without errors once I filled in enough to make it compile.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ShadowManu picture ShadowManu  路  4Comments

goodmind picture goodmind  路  3Comments

lsagetlethias picture lsagetlethias  路  3Comments

Rycochet picture Rycochet  路  4Comments

mirismaili picture mirismaili  路  3Comments