[Solved] ReferenceError: primordials is not defined

I’m trying to upgrade an existing meteor app from 1.8.3 to 1.9 and am getting the following issue when I run the app. Can anybody throw any light on it? I don’t want to get stuck on an old version of meteor if I can’t get it to run any more.

I’ve googled around but noone else with the same issue seems to be using meteorjs. The suggestion is that node12 and gulp are incompatible but I’m not explicitly using gulp. This app has been around since meteor 0.8 and has upgraded OK until now.

Here comes the stack trace - am I right in thinking its the fs module that’s the source of the issue?

Starting backoffice …
[[[[[ ~/ZUUK/meteor/rk-backoffice ]]]]]

=> Started proxy.
=> Meteor 1.10.1 is available. Update this project with ‘meteor update’.
=> Started MongoDB.
W20200414-18:59:12.397(1)? (STDERR) /Users/chris/.meteor/packages/meteor-tool/.
W20200414-18:59:12.415(1)? (STDERR) throw(ex);
W20200414-18:59:12.415(1)? (STDERR) ^
W20200414-18:59:12.416(1)? (STDERR)
W20200414-18:59:12.416(1)? (STDERR) ReferenceError: primordials is not defined
W20200414-18:59:12.416(1)? (STDERR) at fs.js:35:5
W20200414-18:59:12.416(1)? (STDERR) at req_ (/Users/chris/ZUUK/meteor/rk-backoffice/.meteor/local/isopacks/rk-dataset/npm/node_modules/natives/index.js:143:24)
W20200414-18:59:12.416(1)? (STDERR) at Object.req [as require] (/Users/chris/ZUUK/meteor/rk-backoffice/.meteor/local/isopacks/rk-dataset/npm/node_modules/natives/index.js:55:10)
W20200414-18:59:12.416(1)? (STDERR) at Object. (/Users/chris/ZUUK/meteor/rk-backoffice/.meteor/local/isopacks/rk-dataset/npm/node_modules/graceful-fs/fs.js:1:-25)
W20200414-18:59:12.417(1)? (STDERR) at Module._compile (internal/modules/cjs/loader.js:1158:30)
W20200414-18:59:12.417(1)? (STDERR) at Module.Mp._compile (/Users/chris/ZUUK/meteor/rk-backoffice/.meteor/local/build/programs/server/runtime.js:50:23)
W20200414-18:59:12.417(1)? (STDERR) at Object.Module._extensions…js (internal/modules/cjs/loader.js:1178:10)
W20200414-18:59:12.417(1)? (STDERR) at Module.load (internal/modules/cjs/loader.js:1002:32)
W20200414-18:59:12.417(1)? (STDERR) at Module.Mp.load (/Users/chris/ZUUK/meteor/rk-backoffice/.meteor/local/build/programs/server/runtime.js:15:31)
W20200414-18:59:12.417(1)? (STDERR) at Function.Module._load (internal/modules/cjs/loader.js:901:14)
W20200414-18:59:12.417(1)? (STDERR) at Module.require (internal/modules/cjs/loader.js:1044:19)
W20200414-18:59:12.417(1)? (STDERR) at require (internal/modules/cjs/helpers.js:77:18)
W20200414-18:59:12.418(1)? (STDERR) at Object. (/Users/chris/ZUUK/meteor/rk-backoffice/.meteor/local/isopacks/rk-dataset/npm/node_modules/graceful-fs/graceful-fs.js:3:27)
W20200414-18:59:12.418(1)? (STDERR) at Module._compile (internal/modules/cjs/loader.js:1158:30)
W20200414-18:59:12.418(1)? (STDERR) at Module.Mp._compile (/Users/chris/ZUUK/meteor/rk-backoffice/.meteor/local/build/programs/server/runtime.js:50:23)
W20200414-18:59:12.418(1)? (STDERR) at Object.Module._extensions…js (internal/modules/cjs/loader.js:1178:10)
=> Exited with code: 1
=> Your application is crashing. Waiting for file change.

My first thought is that you should check if you have babel-runtime installed and replace it with @babel/runtime using npm

Thanks @coagmano. I tried removing the node_modules folder completely and ran meteor npm install --save @babel/runtime as suggested by the app on it’s first run. Is that what you mean? Unfortunately I still get the error. (I also had to do the same with bcrypt to remove all warnings if that makes any difference)

Yes, but also check if babel-runtime is in package.json and if so run meteor npm rm babel-runtime

Thanks @coagmano. I checked and it was there twice:

"dependencies": {
    "@babel/runtime": "^7.8.4",
    "babel-runtime": "^6.20.0",
    "meteor-node-stubs": "^1.0.0"

but after removing it so that I only had the tagged version I still get the primordials error. Any other thoughts?

Just a quick Google search for “ReferenceError: primordials is not defined”. Looks like this is not a Meteor specific error, but specifically one caused by node v12 and gulp v3: https://timonweb.com/posts/how-to-fix-referenceerror-primordials-is-not-defined-error/

Potential solution: downgrade Meteor, as the older version does not use node v12 until Gulp gets fixed (I personally wouldn’t do that), or stop using Gulp and move completely to NPM (preferable, IMO).

One more edit: < facepalm > my bad, you already say it in your original post </ facepalm >. Maybe try and identify which one of your dependencies uses Gulp, and maybe replace it.

Thanks @illustreets, interesting to see in the link that you sent that it is to do with gulp patching node’s fs module which I’m definitely using.

I’ll try to work out where the gulp dependency is and see if I can’t do something to remove it or pin versions as suggested by the link. Much appreciated.

1 Like

@zuuk I m facing the same problem. Have you found a solution?

@ziedmahdi: I’m afraid not. I got diverted onto something else and haven’t been able to revisit it yet. If you manage to find a solution I’d be grateful if you could share it here. Best of luck!

In my case it was related to webshot, there is already an opened issue there which has some workaround.

@ziedmahdi: that could be our problem too as we have webshot in the dependencies I think. Many thanks for the link.

I have the same error with Meteor 1.10 and this is the error

> node-browser@0.0.3 install /tmp/build_b2551e370bc0a9ade44b669c8d60bbc6/src/node_modules/node-browser
> node ./build.js
} = primordials;
ReferenceError: primordials is not defined
    at fs.js:35:5
    at req_ (/tmp/build_b2551e370bc0a9ade44b669c8d60bbc6/src/node_modules/natives/index.js:143:24)
    at Object.req [as require] (/tmp/build_b2551e370bc0a9ade44b669c8d60bbc6/src/node_modules/natives/index.js:55:10)
    at Object.<anonymous> (/tmp/build_b2551e370bc0a9ade44b669c8d60bbc6/src/node_modules/download/node_modules/graceful-fs/fs.js:1:37)
    at Module._compile (internal/modules/cjs/loader.js:1158:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1178:10)
    at Module.load (internal/modules/cjs/loader.js:1002:32)
    at Function.Module._load (internal/modules/cjs/loader.js:901:14)
    at Module.require (internal/modules/cjs/loader.js:1044:19)
    at require (internal/modules/cjs/helpers.js:77:18)

This was rather annoying, but i found an answer on stackoverflow

  1. add this to your package.json scripts
    "preinstall": "npx npm-force-resolutions"
  1. add this to the root of your package.json
  "resolutions": {
    "graceful-fs": "4.2.3"

@thatshems - that looks like a neat solution. I’ll give it a try. Thanks for letting me know.

Finally got round to looking at this and found that, for me, the issue was being caused by my npm dependency on zip which brought in the incompatible graceful-fs version.

The simple work-around for me was to use zipper instead of zip (they share the same API - so it was a drop-in replacement). Thanks to all for their help in pointing me in the right direction.

1 Like