documentation
documentation copied to clipboard
Cannot read property 'parseExtension' of undefined
First of all thx for this great library, I've been using it with no problems for the past few months however since upgrading to the latest version I'm running into an error.
I'm using documentation version 5.1.1
installed as an npm module. But when I try to run
node generate-docs.js
(see file content of generate-docs below)
I'm getting the following error:
Cannot read property 'parseExtension' of undefined
The error happens in documentation/lib/merge_config.js
at line 72
where the config
passed into the mergeConfig
function is undefined.
I've had the script working on an older version where instead of the returned promise documentation.build() was using callback functions. I've tried to search stackoverflow but documentation is not the easiest search term :) From the documentation I understood that the config.yml
was optional. Any help on a possible solution would be greatly appreciated :)
/* generate-docs.js */
/* eslint-disable no-console */
process.env.NODE_ENV = 'production';
var documentation = require('documentation');
var paths = require('../config/paths');
var streamArray = require('stream-array');
var vfs = require('vinyl-fs');
var files = [
'src/index.js',
'src/entities/player.js'
];
console.log('Building API documentation...');
documentation.build(files, {shallow: true})
.then(documentation.formats.html)
.then(function(output){
streamArray(output).pipe(vfs.dest(paths.appBuildDocs));
console.log('API docs generated');
})
.catch(function(err){
console.log(err);
});
Edit: some additional info, it works for version 4.0.0-beta.18
with the following code:
/* eslint-disable no-console */
process.env.NODE_ENV = 'production';
var documentation = require('documentation');
var paths = require('../config/paths');
var streamArray = require('stream-array');
var vfs = require('vinyl-fs');
var files = [
'src/index.js',
'src/entities/player.js'
];
console.log('Building API documentation...');
documentation.build(files, {shallow: true}, function(err, res) {
if(err) {
console.error(err);
return;
}
documentation.formats.html(res, {}, function(err, output) {
streamArray(output).pipe(vfs.dest(paths.appBuildDocs));
console.log('API docs generated');
});
});
I ran into this as well with the markdown formatter. It seems the formatter's options
parameter (second parameter) is required.
You should be able to use it like this:
/* generate-docs.js */
/* eslint-disable no-console */
process.env.NODE_ENV = 'production';
var documentation = require('documentation');
var paths = require('../config/paths');
var streamArray = require('stream-array');
var vfs = require('vinyl-fs');
var files = [
'src/index.js',
'src/entities/player.js'
];
console.log('Building API documentation...');
documentation.build(files, {shallow: true})
.then(comments => documentation.formats.html(comments, {}))
.then(function(output){
streamArray(output).pipe(vfs.dest(paths.appBuildDocs));
console.log('API docs generated');
})
.catch(function(err){
console.log(err);
});
Maintainers, do the docs needs to be updated for the formatters? Or is the intent that the options should be optional?
I think we need to make optional the second parameter.
I encounter the same issue in 5.3.5
.
This still happen today using ^8.0.0 and copy paste node markdown example execute it and you get a:
TypeError: Cannot read property 'parseExtension' of undefined
node_modules\documentation\lib\merge_config.js:92:35)
Even using a empty object as second parameter
Edit: Actually using v6.2.0, which is the latest release as github says, it works! I dunno why npm installed the v8.x when running npm install documentation
Version 9.1.1 and this happens again during the standard HTML generation. Adding the second option: {shallow: false} fixes it
Version 13.0.1, same when trying to generate markdown. {shallow: false} as a second option fixes it.