Meteor app not finding 'xhr-sync-worker.js'?

Viewed 905

I am trying to run a deck.gl example inside a meteor app. But I am facing this error.

modules-runtime.js?hash=8587d18…:231 Uncaught Error: Cannot find module './xhr-sync-worker.js'
    at makeMissingError (modules-runtime.js?hash=8587d18…:231)
    at Function.require.resolve (modules-runtime.js?hash=8587d18…:263)
    at xmlhttprequest.js (xml.js:30)
    at fileEvaluate (modules-runtime.js?hash=8587d18…:343)
    at require (modules-runtime.js?hash=8587d18…:238)
    at Window.js (xml.js:30)
    at fileEvaluate (modules-runtime.js?hash=8587d18…:343)
    at require (modules-runtime.js?hash=8587d18…:238)
    at api.js (xml.js:30)
    at fileEvaluate (modules-runtime.js?hash=8587d18…:343)

However the said js module is present in the meteor app node_modules folder.

/caseview/node_modules/jsdom/lib/jsdom/living/xhr-sync-worker.js

How can I make my app see it?. Note That I am not importing it directly in my code, as can be seen from the stack trace above. Perhaps this is a meteor bug.

4 Answers

I just ran into this problem and was able to resolve my issue, so I thought I'd include it here for posterity.

I had added JSDOM through NPM, and inadvertently required jsdom on both my client side and server side code.

By wrapping the require in a Meteor.isServer condition I resolved my problem.

if (Meteor.isServer) {
  const jsdom = require("jsdom");
}

So if you are running into this issue double check you are not trying to run the code on the client unintentionally.

I also had the same problem and it seemed to disappear when I renamed the file I was requiring JSDOM in from index.js to index.es6. I believe it have to do with the ...require(); function.

Late reply but I was facing the same problem in a meteor / react app, trying to import JSDOM in a component. After some long hours there's a way. Step 1 : JSOM library use relative path for require :

node_modules/jsdom/lib/jsdom/living/xhr/XMLHttpRequest-impl.js:31
const syncWorkerFile = require.resolve ? require.resolve("./xhr-sync-worker.js") : null;

Meteor build all your code so the relative path is no longer ok. Solution : replacing this line with an absolute path :

const syncWorkerFile = "${require.resolve('jsdom/lib/jsdom/living/xhr/xhr-sync-worker.js')}";

Now your app is working but if you do a meteor npm install you will have to redo this modification.

Step 2 : create and use your own package in node_modules/jsdom do a yarn pack to generate a tar.gz with your modification (jsdom use yarn so you can't use npm)

move your archive : cp ./jsdom-v18.1.1.tgz ../../dependencies/

and replace jsdom with yours freshly build: meteor npm install dependencies/jsdom-v18.1.1.tgz

Related