Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Cannot find module 'documentation' #1482

Open
bobbrowning opened this issue Feb 17, 2022 · 5 comments
Open

Error: Cannot find module 'documentation' #1482

bobbrowning opened this issue Feb 17, 2022 · 5 comments

Comments

@bobbrowning
Copy link

bobbrowning commented Feb 17, 2022

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
Copy link
Author

bobbrowning commented Feb 18, 2022

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

Lacks elegance but works for my purposes.

@tmcw
Copy link
Member

tmcw commented Feb 18, 2022

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

@bobbrowning
Copy link
Author

bobbrowning commented Feb 19, 2022

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)

@brenthompson
Copy link

brenthompson commented Feb 27, 2024

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

@tmcw
Copy link
Member

tmcw commented Feb 27, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants