2

I am seeing this error running my Nuxt project:

require() of ES Module /Users///node_modules/d3/src/index.js from /Users///node_modules/vue-server-renderer/build.dev.js not supported.

Instead change the require of index.js in /Users/*//node_modules/vue-server-renderer/build.dev.js to a dynamic import() which is available in all CommonJS modules.

it points to this:

node_modules/vue-server-renderer/build.dev.jsopen in editor
            file = path$1.posix.join('.', file);
            if (files[file]) {
                return evaluateModule(file, sandbox, evaluatedFiles);
            }
            else if (basedir) {
                return require(resolvedModules[file] ||
                    (resolvedModules[file] = resolve.sync(file, { basedir })));
            }
            else {
                return require(file);
            }

I am unsure why it is throwing this error?

user1072337
  • 12,615
  • 37
  • 116
  • 195
  • 1
    You can't use `require` with a ES6 module. I don't understand the question. The question contains the description and the solution. – jabaa Sep 23 '22 at 20:49
  • What exactly do I change so the project still works? – user1072337 Sep 23 '22 at 21:41
  • `require() of ES Module not supported.` `Instead change the require to a dynamic import() which is available in all CommonJS modules.` – jabaa Sep 23 '22 at 22:14
  • 1
    [Using the dynamic import() function on Node.js](https://stackoverflow.com/questions/58858782/using-the-dynamic-import-function-on-node-js) – jabaa Sep 23 '22 at 22:16
  • @jabaa I checked a clean build of Nuxt, and it has exactly the same code as for that build.dev.js files as this one, so not sure what's happening - but I don't think I need to change the build.dev.js file manually - it's a node module. – user1072337 Sep 24 '22 at 18:52
  • If this is a problem with the module, you should ask here: https://github.com/nuxt/nuxt.js/issues – jabaa Sep 24 '22 at 20:09
  • I kind of have the same issue. It is very weird, because I logged `resolvedModules` and the file that breaks things is `/node_modules/ol/index.js ` (https://github.com/openlayers/openlayers/blob/main/src/ol/index.js) and I don't see any require in there... :s If you have found a solution @user1072337, I would be very glad if you shared it. – Merc Mar 14 '23 at 12:22

0 Answers0