Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot statically analyse 'require(…, …)' in line 16

I am using nextjs.

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
like image 618
Rahul Avatar asked Oct 22 '25 06:10

Rahul


1 Answers

When going through the lib code:

'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');

require gets overwritten by the library utils assignment (although it seems like a terrible idea).

I don't know what bundler you use, but this is probably the source of the problem as it tries to evaluate the require with two parameters, which it cannot do.

I would log a Github ticket to use another identifier than require and fix the source of the problem.

like image 149
html_programmer Avatar answered Oct 24 '25 20:10

html_programmer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!