markdown-toc
markdown-toc copied to clipboard
Error: Cannot statically analyse 'require(…, …)' in line 16
See: https://stackoverflow.com/questions/69898244/cannot-statically-analyse-require-in-line-16
Problem:
When importing markdown-toc in nextjs I am getting the issue. /pages/index.js
import toc from "markdown-toc";
Then I got the below error
./node_modules/markdown-toc/lib/utils.js Cannot statically analyse 'require(…, …)' in line 16
Why:
require
gets overwritten by the utils assignment here:
'use strict';
/**
* Module dependencies
*/
var diacritics = require('diacritics-map');
var utils = require('lazy-cache')(require);
var fn = require;
require = utils;
/**
* Lazily required module dependencies
*/
require('concat-stream', 'concat');
Any update on this?
I'm having the same error when importing the library in an Angular 14 application...
I don't believe there will be, there are > 50 open issues and no update in the last 5 years.
This fixed the problem but maybe you have to mess with dependencies...
Copy the library and put it in another folder to edit the source of it, then remove this:
var fn = require;
require = utils;
And replace all the require(..., ...)
with utils(..., ...)
like this:
utils('concat-stream', 'concat');
utils('gray-matter', 'matter');
utils('list-item', 'li');
utils('markdown-link', 'mdlink');
utils('minimist');
utils('mixin-deep', 'merge');
utils('object.pick', 'pick');
utils('remarkable', 'Remarkable');
utils('repeat-string', 'repeat');
utils('strip-color');
Hope it helps!
Ok, I think I have a better solution. Try this: "markdown-toc-unlazy" https://www.npmjs.com/package/markdown-toc-unlazy
And if you don't need to work with cli
you can delete the file cli.js
and in the libs/utils.js
file remove this line at the start:
var concat = require('concat-stream');
.
Hope this helped you!