markdown-link-check icon indicating copy to clipboard operation
markdown-link-check copied to clipboard

Nested links lint triggers error with Node.js but not with npx

Open yoriiis opened this issue 2 years ago • 10 comments

Using markdown-link-check through Node.js triggers an error while using through npx does not.


With the following files

README.md

# Title

[nested content](./docs/README.md)

docs/README.md

# Nested doc

With the npx command, it works.

npx markdown-link-check README.md

With Node.js it does not works.

node lint.js

lint.js

const fs = require('fs');
const markdownLinkCheck = require('markdown-link-check');

fs.readFile('README.md', 'utf8', (err, data) => {
	if (err) {
		console.error(err);
		return;
	}

	markdownLinkCheck(data, function (err, results) {
		if (err) {
			console.error('Error', err);
			return;
		}
		results.forEach(function (result) {
			console.log('%s is %s', result.link, result.status);
		});
	});
});

The following error appears:

node:internal/url:560
      throw new ERR_INVALID_URL(input);
      ^

TypeError [ERR_INVALID_URL]: Invalid URL
    at new NodeError (node:internal/errors:399:5)
    at new URL (node:internal/url:560:13)
    at linkCheck (/Users/xxx/demo/node_modules/link-check/index.js:21:47)
    at /Users/xxx/demo/node_modules/markdown-link-check/index.js:119:9
    at /Users/xxx/demo/node_modules/async/dist/async.js:246:13
    at replenish (/Users/xxx/demo/node_modules/async/dist/async.js:446:21)
    at /Users/xxx/demo/node_modules/async/dist/async.js:451:13
    at _asyncMap (/Users/xxx/demo/node_modules/async/dist/async.js:244:16)
    at Object.mapLimit (/Users/xxx/demo/node_modules/async/dist/async.js:2091:16)
    at Object.awaitable [as mapLimit] (/Users/xxx/demo/node_modules/async/dist/async.js:211:32) {
  input: './docs/README.md',
  code: 'ERR_INVALID_URL'
}

The error is trigger with the following line on link-check.

yoriiis avatar Jul 10 '23 14:07 yoriiis

@tcort Could you look at this issue please? Thanks

yoriiis avatar Apr 02 '24 14:04 yoriiis