npm run gulp primordials not defined - node.js

I'm trying to run npm run gulp and I'm coming up with this primordials is not defined error (I have also added the npm-shrinkwrap.json file as suggested which gets updated after running npm install but it doesn't fix my primordials is not define error):
> gulp-tutorial#1.0.0 gulp
> gulp
fs.js:47
} = primordials;
^
ReferenceError: primordials is not defined
at fs.js:47:5
at req_ (/Applications/MAMP/htdocs/wordpress/wp-content/themes/theming-main/node_modules/natives/index.js:143:24)
at Object.req [as require] (/Applications/MAMP/htdocs/wordpress/wp-content/themes/theming-main/node_modules/natives/index.js:55:10)
at Object.<anonymous> (/Applications/MAMP/htdocs/wordpress/wp-content/themes/theming-main/node_modules/vinyl-fs/node_modules/graceful-fs/fs.js:1:37)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1147:10)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:102:18)
Node.js v17.0.1
Any suggestions 🙌 ?

Primordials are used by Node.js internal modules and are not accessible to end user scripts. (That's their entire point for existing. Otherwise, you could modify Object.prototype and end up affecting Node.js internals, causing weird crashes and things like that.)
The module that is giving you this error is the natives module. The page for the package says:
This module relies on Node.js's internals and will break at some point. Do not use it, and update to graceful-fs#4.x.
Sounds like it's at that point where it's broken. Use npm ls natives to find out what's using it. (You might need to be in the /Applications/MAMP/htdocs/wordpress/wp-content/themes/theming-main directory when you run the command.) From there, you can try to figure out how to get rid of it.
Another possibility would be to try downgrading to an earlier version of Node.js to see if it works with that version.

The problem was with the versions not matching up. I also had 2 NodeJS installation paths and that was throwing things off.
I uninstalled them all, started from the beginning and used brew to reinstall.
Then checked that the versions were all compatible.
I also had to install node-sass and referred to this compatibility table to get the correct version - https://github.com/sass/node-sass#node-version-support-policy
Now its working and I can get on developing :) As of today Im running Node v17.0.1 Npm v8.1.0 Gulp cli v2.3.0

Related

How to fix ReferenceError: primordials is not defined in node v13.12.0

I am trying to install krakenjs using the guide available on http://krakenjs.com/
when i am trying to run yo kraken this command i get this error
fs.js:39
} = primordials;
^
ReferenceError: primordials is not defined
at fs.js:39:5
at req_ (C:\Users\KIIT\AppData\Roaming\npm\node_modules\generator-kraken\node_modules\natives\index.js:143:24)
at Object.req [as require] (C:\Users\KIIT\AppData\Roaming\npm\node_modules\generator-kraken\node_modules\natives\index.js:55:10)
at Object.<anonymous> (C:\Users\KIIT\AppData\Roaming\npm\node_modules\generator-kraken\node_modules\graceful-fs\fs.js:1:37)
at Module._compile (internal/modules/cjs/loader.js:1147:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
at Module.load (internal/modules/cjs/loader.js:996:32)
at Function.Module._load (internal/modules/cjs/loader.js:896:14)
at Module.require (internal/modules/cjs/loader.js:1036:19)
at require (internal/modules/cjs/helpers.js:72:18)
using following versions
node: 13.12.0
gulp
CLI version: 2.2.0
Local version: 4.0.2
The generator-kraken module seems to be using natives as a dependency. The natives module has been deprecated, and doesn't behave consistently across all versions of node.
You could use Node v10 to run generator (yo kraken command). Yomen generator (yo) only spits out static code. Once your code has been generated you can return back to node 13, if required. Since kraken itself doesn't have any dependency on natives, you shouldn't face any problem running the generated code with node 13. You can use nvm to quickly switch between versions of node, if you aren't already.
Another viable option would be to skip the 'generator' altogether and start with one the examples repos mentioned on Kraken home page here. You could clone one of those repositories and adapt it to your use. Or, use them as reference and create your own setup from scratch.

Using nodejs bindings to run native c++ code produces an error

I'm trying to develop an electron app, and I would like to use an npm package that gives vibrancy to a window. This is the package I'm trying to use: https://github.com/sebascontre/windows10-fluently-vibrancy
It uses a visual c++ code to call native windows methods to achieve this vibrancy effect.
I've cloned and I've run the npm install and build as described in the readme and ran the following:
npm install
npm run conf
npm run rebuild
All built successfully and I also see the build\debug artifacts of the c++ build.
When I try to run it (as described in readme):
cd spec\app
electron .
I'm getting the following error message:
Uncaught Exception:
Error: The specified module could not be found.
\\?\F:\Development\windows10-fluently-vibrancy\build\Debug\Vibrancy.node
at process.func [as dlopen] (electron/js2c/asar.js:155:31)
at Object.Module._extensions..node (internal/modules/cjs/loader.js:857:18)
at Object.func [as .node] (electron/js2c/asar.js:155:31)
at Module.load (internal/modules/cjs/loader.js:677:32)
at tryModuleLoad (internal/modules/cjs/loader.js:609:12)
at Function.Module._load (internal/modules/cjs/loader.js:601:3)
at Module.require (internal/modules/cjs/loader.js:715:19)
at require (internal/modules/cjs/helpers.js:14:16)
at bindings (F:\Development\windows10-fluently-vibrancy\node_modules\bindings\bindings.js:112:48)
at Object.<anonymous> (F:\Development\windows10-fluently-vibrancy\index.js:1:35)
According to the message it cannot find the Vibrancy.node file - But I've verified that it exists in the specified location.
Any ideas how to make it run? I have cloned the package to test it since when trying to use the npm itself in my project it gave the same error so I figured I would try the source.
Today I had the exact same issue you're describing here.
I got it to work using electron-rebuild.
From the root of your project run the command: electron-rebuild
Hope this helps you, if not, maybe someone else.

"Foundation - ReferenceError: primordials is not defined when starting a foundation zurb project."

Getting an error when creating a Foundation Zurb project. Tried to solve using the previous suggestions shown for other applications, but none are working.
A post referenced updating elm, and I did so, however, it did not work. Additionally, I reviewed the closed issue for Gulp 3 (i am using gulp 4), but there was not viable fixes (Gulp 3 is broken on Node 12 #2324) or workarounds.
$ foundation new --framework emails
fs.js:27
const { Math, Object } = primordials;
^
ReferenceError: primordials is not defined
at fs.js:27:26
at req_ (/usr/lib/node_modules/foundation-cli/node_modules/natives/index.js:143:24)
at Object.req [as require] (/usr/lib/node_modules/foundation-cli/node_modules/natives/index.js:55:10)
at Object.<anonymous> (/usr/lib/node_modules/foundation-cli/node_modules/graceful-fs/fs.js:1:37)
at Module._compile (internal/modules/cjs/loader.js:759:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
at Module.load (internal/modules/cjs/loader.js:628:32)
at Function.Module._load (internal/modules/cjs/loader.js:555:12)
at Module.require (internal/modules/cjs/loader.js:666:19)
at require (internal/modules/cjs/helpers.js:16:16)
I expect the project to build.
I guess you use NodeJS 12 or newer.
NodeJS 12 (and newer) is (currenctly) not supported by the current CLI. Please use NodeJS 10.
You can switch to NodeJS 10 using nvm, n, nodenv or any other solution for managing NodeJS versions.
primordials is part of the natives package and called in the graceful-fs package as you can see in the stacktrace.
You can try to upgrade the graceful-fs dependency from 3 to 4 but this might not work without other changes.
This is in fs.js of graceful-fs 3:
module.exports = require('natives').require('fs', ['stream'])
From the natives page on npmjs.com:
This package has been deprecated
Author message:
This module relies on Node.js's internals and will break at some point. Do not use it, and update to graceful-fs#4.x.
Also see https://travis-ci.com/DanielRuf/foundation-cli-test/builds/112738932
Compare this to the environment where we have NodeJS 10 (the team of gulp has deleted the 4.0 tag, you can change the line in package.json to reference gulp 4.0.0):
Works for me using the
Manual Setup (node v13.7.0)
To manually set up the template, first download it with Git:
git clone https://github.com/zurb/foundation-emails-template "projectname"
Then open the folder in your command line, and install the needed dependencies:
cd projectname
npm install

Error: Module version mismatch - without removing node_modules

When trying to start up my application using node app.js I'm getting this error:
lucas#XYZ:~/app/lucas$ node app.js
module.js:583
return process.dlopen(module, path._makeLong(filename));
^
Error: Module version mismatch. Expected 48, got 57.
at Error (native)
at Object.Module._extensions..node (module.js:583:18)
at Module.load (module.js:473:32)
at tryModuleLoad (module.js:432:12)
at Function.Module._load (module.js:424:3)
at Module.require (module.js:483:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/lucas/app/lucas/node_modules/canvas/lib/bindings.js:3:18)
at Module._compile (module.js:556:32)
at Object.Module._extensions..js (module.js:565:10)
When I type in node -v I get v6.5.0
As this website shows, this corresponds to version 48, so where the 57 is coming from?
I know the default solution is deleting node_modules but I'd like to understand what's going on here and try to avoid that, and any other similar approaches that involve reinstalling all modules etc. Question is more about understanding the actual problem.
EDIT: If you're curious whats in that bindings.js file this is all that's inside:
'use strict';
module.exports = require('../build/Release/canvas.node');
Simply put Node 6.x is trying to open a native module built for Node 8.x.
Based on the traceback, it's the canvas module – you've somehow ended up with a newer native module for canvas in your node_modules than the Node you're running with. (One way this can happen is by using nvm, n or other node version manager.)
You don't necessarily have to nuke all of node_modules to fix this (though it doesn't hurt, and if you have a project that doesn't survive nuking node_modules, that's a problem in itself) – you could try renaming node_modules/canvas to node_modules/canvas.backup or something and running npm install (or yarn install) again (with the correct Node version active) and it should download/recompile the native module for canvas as it's reinstalling the now "missing" canvas.

Cannot find module connect/utils when installing node+express

I just installed node by cloning the git repo + make && make install. I then installed npm, and used npm to install express (seems like it fetches connect automatically since it's a dependency). However, when trying to start a simple express example i get the error message:
Error: Cannot find module 'connect/utils'
at Function._resolveFilename (module.js:219:11)
at Function._load (module.js:171:25)
at require (module.js:246:19)
at Object.<anonymous> (/home/yngve/local/node/lib/node/.npm/express/1.0.3/package/lib/express/response.js:16:13)
at Module._compile (module.js:302:26)
at Object..js (module.js:308:10)
at Module.load (module.js:234:31)
at Function._load (module.js:201:10)
at require (module.js:246:19)
at Object.<anonymous> (/home/yngve/local/node/lib/node/.npm/express/1.0.3/package/lib/express/index.js:52:1)
Seems someone has the same problem here: http://groups.google.com/group/express-js/browse_thread/thread/287086bd30f79cf1/adbb5c669872e45a
but the conclusion seems to be that one needs connect installed (which I have).
I've checked that I have the following files at least:
/home/yngve/local/node/lib/node/.npm/connect/0.5.8/package/lib/connect/utils.js
/home/yngve/local/node/lib/node/.npm/express/1.0.3/node_modules/connect/connect/utils.js
Anyone have a clue?
Resolved
Added
require.paths.unshift('<path_to_node>/lib/node/connect');
But the newest rev. is fixed, so this shouldn't really be necessary (see answer below).
It seems like it was a bug in express. Installing the latest version, 1.0.5, fixed this problem for me.
It sounds like you don't have your require path including your npm directory. Use require.paths to modify that.
Some more info:
http://jherdman.github.com/2010-04-05/understanding-nodejs-require.html

Resources