Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

./node_modules/markdown-toc/lib/utils.js
Cannot statically analyse 'require(…, …)' in line 16

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading