documentation icon indicating copy to clipboard operation
documentation copied to clipboard

Error: Cannot find module 'documentation'

Open bobbrowning opened this issue 3 years ago • 5 comments

I am trying to use the API. I installed documention.js (13.2.5) using npm (6.14.16) and it is working fine from the command line. However this does not generate a module in node_modules and when I run a program with

var documentation = require('documentation');

I get

Error: Cannot find module 'documentation'

How do I install the module. I can't find instructions in the documentation..

bobbrowning avatar Feb 17 '22 12:02 bobbrowning

I have a workaround at lease... exec( documentation build ./bin/suds/admin.js --shallow -f md | markdown, ....

Lacks elegance but works for my purposes.

bobbrowning avatar Feb 18 '22 10:02 bobbrowning

The default instructions - npm install -g documentation - are to install documentation globally, as a command-line tool. If you'd like to install it locally, so you can use it with require, you can drop the -g argument and run npm install documentation

tmcw avatar Feb 18 '22 14:02 tmcw

Thanks. I eventually found the module in /lib and tried requiring it from there, but came up with an error so abandoned that approach. I just re-installed documentation as suggested and I am getting the same error.

The code let documentation=require ('documentation'); let sendView = require('./suds/send-view');

module.exports = async function (req, res) { documentation.build([req.query.file]) .then(documentation.formats.html) .then(output => { let result = sendView(res, 'report', output); }); return('OK'); }

req.query.field has the path/file name (./suds/db.js) and sendView sends the results to the screen.

TypeError: Cannot read property 'parseExtension' of undefined at mergeConfig (/home/bob/ex/suds/base/node_modules/documentation/src/merge_config.js:84:35) at configure (/home/bob/ex/suds/base/node_modules/documentation/src/index.js:48:24) at Object.build (/home/bob/ex/suds/base/node_modules/documentation/src/index.js:225:34) at module.exports (/home/bob/ex/suds/base/bin/docs.js:29:17)

bobbrowning avatar Feb 19 '22 12:02 bobbrowning

The default instructions - npm install -g documentation - are to install documentation globally, as a command-line tool. If you'd like to install it locally, so you can use it with require, you can drop the -g argument and run npm install documentation

This doesn't work on version 14.0.3 or later.

$ cat require.js

const doc = require('documentation')
console.log(doc)
# node ./require.js
/Users/brentthompson/Projects/temp/doctest2/require.js:1
const doc = require('documentation')
            ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/brentthompson/Projects/temp/doctest2/node_modules/documentation/src/index.js from /Users/brentthompson/Projects/temp/doctest2/require.js not supported.
Instead change the require of index.js in /Users/brentthompson/Projects/temp/doctest2/require.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Users/brentthompson/Projects/temp/doctest2/require.js:1:13) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.18.2

brenthompson avatar Feb 27 '24 18:02 brenthompson

Yes, looks like the changelog mentions updating to node v14 but not the move to native esm.

You'll need to use import for 14.x

tmcw avatar Feb 27 '24 19:02 tmcw