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

Time:11-09

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

CodePudding user response:

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.

  • Related