1

I am working on a legancy project and it requires to use nodeJs version 4. My development machine is - Windows 10 64 bit. I am using NVM to manage node version.

None of my NPM scripts work in NodeJs V4. It always return this error message:

    $ node -v
    v4.2.0

    npm i or npm -v
    /c/Program Files/nodejs/npm: Segmentation fault "$NODE_EXE" "$NPM_CLI_JS" "$@"

Does anyone have any clue? NPM scripts are not working in my local machine if I switch to NodeJs version < V7, However, if I switch to any node version >= V7, NPM is working

I also try to completely uninstall NodeJS and re-install it. Nothing works.

It is not my decision to use such an old version of Nodejs. My organization uses it and I can't change it.

Kevin
  • 272
  • 5
  • 21
  • 3
    ... sorry, are you sure? Because Nodejs 4.0 is from 2015. As for your NPM scripts failing: that's not the error you got, please show the unedited, full error. – Mike 'Pomax' Kamermans Oct 28 '21 at 00:06
  • I am sure. It is a very very old project and it only work for NodeJs 4.2.0 – Kevin Oct 28 '21 at 00:07
  • fair enough, but again: please show the full, unedited error. – Mike 'Pomax' Kamermans Oct 28 '21 at 00:13
  • If I use Git Bash, this is the only error I got. Nothing else. If I use Powershell and commond prompt, it didn't log any error. And also I have double checked, I didn't hide the error scripts when setting up NPM – Kevin Oct 28 '21 at 00:17
  • 1
    then please show exactly that: copy paste the console log starting at showing both the `node -v` and `npm -v` run, show the `npm run ...` command and its output, and show your package.json so people can see what your npm script is even trying to run please. Right now, [there are not enough details](/help/how-to-ask) for anyone to tell you what's wrong. – Mike 'Pomax' Kamermans Oct 28 '21 at 00:19
  • 1
    If it works on your _"own dev machine"_, where exactly does it not work? For something like this with such an ancient version of Node, I'd definitely be running it in Docker – Phil Oct 28 '21 at 00:34
  • Also please share the package.json of your project, a better solution would also be to find why the project can't be run on latest node versions and solve that, rather than forcing to work with an old engine; Working on such old packages is hardly ever a good idea – ale917k Oct 31 '21 at 14:31
  • since there isn't anything for test the changes and result, I'll trying to guess the issue, please give feedback about the result – nima Oct 31 '21 at 16:39

1 Answers1

2

This is a bit of a weird issue and without more error logs or information I'm, at best, guessing at an answer, but I researched a bit because I thought this was pretty interesting.

"npm ERR! errno 3221225477" Error in Node when making a query using oracledb

There is a similar question that was previously asked, I don't know if that might be the complete error log for you as well, your node might just be suppressing it or something. The windows access violation there refers to a segment fault.

https://askubuntu.com/questions/641804/npm-v-return-segmentation-fault

There was also a similar question so it's not just related to windows. What's also interesting is that the person asking there installed on ubuntu using software center and not apt, so it might be something to do with npm not installing correctly since software center is usually bugged as hell.

https://github.com/breejs/bree/issues/103

It was also mentioned in quite a few git issues but all of them seem to be closed before anyone ever contributed more to it. Also interesting is that most of them started around 2020.

https://github.com/nodejs/help/issues/3145

There is another issue where someone said they got it because of unescaped bash script quotes.

Some people have mentioned that it's an issue related to your firewall, but I doubt that's the case if it's also happening on linux. Another person on the other hand said running it on linux it suddenly worked. It doesn't seem to me like it has anything to do with the platform.

Even more info is that a segment fault, https://en.wikipedia.org/wiki/Segmentation_fault, is caused when your software is trying to access either faulty or protected memory in which case the hardware will throw a segment fault error and shut down the process.

I also learned that if your code is using native packages built for a wrong version of node, it can also lead to a segment fault, in which case you'll either have to upgrade node or you'll have to rebuild those packages for the correct version.

I believe, just an utterly intuitive guess, that node isn't installing correctly or that something with the way it's installed is causing it to incorrectly access memory in a way it shouldn't. I think you should do a forced npm cache clean and also make sure that you've actually entirely uninstalled both npm and node, also purged all related files to both of them, then reinstall. Make sure you delete everything for node and npm, not just node, otherwise you might be trying to run the latest npm with a very old node which won't work. I also don't think you should be using NVM for such an older version of node, maybe it works, but I dunno, so if all else fails download the specific version you want from https://nodejs.org/en/download/releases/ or compile it from source yourself.

I thought this issue was pretty interesting so if you do end up finding a solid solution to it I'd like to know what exactly it was.

  • Another issue is that you may have to add node to the path you can do this during installation or manually. https://stackoverflow.com/questions/27864040/fixing-npm-path-in-windows-8-and-10 – xi_darius Nov 05 '22 at 19:39