Node serving an old version but still compiles updates - node.js

I'm creating a React application and am running into this issue. When I make changes to code, Node does recompile and even recognizes errors in the code, but no matter what, the localhost in the browser remains unchanged. Here's a list of things that I've tried:
Clearing the browser's cache and hard reloading the page
Switching browsers
Turning Node off and on again
Reinstalling Node
Creating a new directory, copying over the code, and then installing Node there
Turning the whole computer off and on again
I'm not sure what to try anymore. When installing Node, there are no errors, and no errors if I run npm start or npm build. As I said, I know Node is looking in the right directory since it recognizes when I make changes and shows errors when the code fails to compile. I also know I'm looking at the right localhost page since it isn't available when Node isn't running. However, the page remains perfectly usable and unchanged even if the code fails to compile, and actually is able to load before Node compiles all of the code.
I got the code itself from a zip file from GitHub and people who have their frontend set up have no issues with it. Node and all the other dependencies were downloaded by me, again, with no errors.
I'm using Node v10.16.0 and npm v6.9.0

Related

Node JS Randomly stops executing - Shows no errors

I am not sure where to start looking for the issue here.
I recently updated from angular 5 to angular 8. The application runs fine after the update. I don't know if this is related.
All of the sudden, my Node JS scripts stop seemingly at random. Sometimes they run, usually they don't. This is any script.
By "Stopping" I mean the console, mid execution, leaves the last line it wrote up, and on the next line, I am able to write more commands.
Example:
C:\location\> npm start
ng serve --aot
** Angular Live development server is listening on .....*
12 % building 22/23 modules 1 active ...somefile.ts
C:\location\>
There is no error, even when I run --verbose. Also, if I have multiple windows up or multiple servers running, they all stop at the same time. It is happening regardless of the application or package, including http-server, Angular, and installing dependencies.
I couldn't find anything related online. Has anyone ever seen this?
Update:
The issue is caused by my lack of CPU.
I thought I fixed it by updating, but that didn't work.
----------- (previous reply, not a solution)
It appears some of my installed dependency versions conflicted with package.json. Basically something did not fully update as expected.
I resolved the issue by running npm install.

Laravel Mix HMR not updating after compiling

I have Laravel Mix 4.0.13 installed.
npm run watch works great, and running npm run hot it does seem to compile and detect my changes, recompiling.
However, nothing changes in the browser. In the console I see:
[HMR] Waiting for update signal from WDS...
[WDS] Hot Module Replacement enabled.
And after compiling, I get the following message twice, every time I compile:
[WDS] App updated. Recompiling...
I assume there needs to be another message that says reloading or something?
Another strange thing, if I try to refresh the page, it never loads anything from localhost:8080. It just sits there waiting indefinitely. I have to restart npm run hot and then reload the page.
Both JS/Vue and SASS doesn't reload in the browser.
You probably use .version() in your mix file.
Like in the docs, versioning in development is not very useful, so you could;
if (mix.inProduction()) {
mix.version();
}
Docs: https://laravel.com/docs/5.8/mix#versioning-and-cache-busting
It seems there is a problem with mix.version(). After removing .version() from my webpack.mix.js file, everything appears to work.
Also maybe file is in different case, like 'element.vue' or 'Element.vue'
Make sure you include manifest.js in the page

Angular application throws exception at compile time

I have an Angular 2 application, running in Electron and using Knex for database interaction that has successfully compiled and run several times over. After several edits, I attempted to run the application locally and received the error ReferenceError: "yexecutor is not defined".
Googling the error yielded no results. I have gradually commented out every line of custom code written by me and still the error occurs. I've even rebooted my rig thinking, perhaps, Node was just acting up. After a reboot, I'm still getting the error.
After commenting all of my own code, rebooting and finally dying and coming back to life to try again, I remembered I was investigating the source of some of the packages I had installed. So, I decided to try deleting the node_modules directory and execute an npm install.
A few minutes later, I'm back to a successful compile!
Steps to solve:
Delete node_modules
npm install
I must have fat fingered the keyboard while meandering through the packages! That, or my cats decided to become contributors.
Viola!

PhantomJS from Node on Windows

I have written a Electron application using Node, Electron Boilerplate, and phantom. It works perfectly fine for me on my linux machine, I copied the source over to Windows 10, and ran with npm start, and all goes smoothly.
However, when I try to build the application with the boilerplate module using npm run release, things go a little less smoothly. I can install and open the application just fine, but when I click the button that activates the phantom module, the windows goes all white and nothing happens. I was able to logs some errors with the dev tools.
First, I have:
C:\...\dist\win-unpacked\resources\app.asar\node_modules\phantom\lib\phantom.js:361
Uncaught (in promise) Error: Error reading from stdin: Error: write EPIPE(…)
I did some research into similar issues, namely here, and it seems to me the issue is starting the child process, PhantomJS, with the npm module phantom. Originally, I was using a WPF application I wrote in C# to start the process, and that worked just fine. This leads me to believe that the phantom module is the culprit.
So I tried swapping out the npm phantom module for horseman, but got similar results:
Unhandled rejection HeadlessError: Phantom immediately exited with: 4294967295
at ChildProcess.immediateExit (C:\...\dist\win-unpacked\resources\app.asar\node_modules\node-horseman\node_modules\node-phantom-simple\node-phantom-simple.js:153:23)
at ChildProcess.g (events.js:286:16)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:204:12)
Here is a shot in the dark. I am not positive this will solve your issue but here it goes:
GYP and miss-matched binaries
Phantom and many other node modules use binaries built for the specific OS that it will be running on. Sometimes in your npm log files you will see references to node-gyp. Node-gyp simply helps to build native add-on's in node modules. When the binaries are built they are usually built against, among others, three main parameters, the operating system, cpu architecture and version of node that is doing the installation.
I think you need to rebuild phantomjs to the version of node Electron is using. Most of the time the node version you have installed on your machine and the node version running in Electron are not the same. Electron does its best to keep up, but there is always a little lag because of the amount of work and testing required to keep up-to-date.
When you install phantom by running npm install phantom it will assume it needs to install or build the binaries for the node version your machine is using. Then when your Electron app tries to run phantom it tries to call the binary of the Electron's node version. When it isn't there the child process immediately exits with an error.
How to fix
Luckily, there are other people out there that have figured out how to fix this issue and have created a great tool to help generate the correct binaries.
Enter electron-rebuild:
https://github.com/electron/electron-rebuild
Electron-rebuild can be run in the command line, and it will rebuild all of your native modules to the version of Electron your project is using.
To install:
npm install electron-prebuilt
To use (in Windows):
.\node_modules\.bin\electron-rebuild.cmd
This should be enough to put the correct binaries in the right place.
Other thoughts
Sometimes you can use a package that uses a dependency called node-pre-gyp. E.g. sqlite3. There is a known issue I ended up running into when trying to rebuild my packages for Electron. Basically, in order to avoid this issue (if you run into it) just append --pre-gyp-fix to the above command.
Tangent for those who run into the pre-gyp-fix issue
One more thing on the pre-gyp-fix: If one or more of your dependencies depends on one of the modules that need the pre-gyp-fix then they will be looking for the binary in the wrong place even if they are running in Electron. All of the pre-gyp binaries are stored in a folder similar to this:
.\node_modules\sqlite3\lib\binding
In my current project I have three folders here, one for Electron-v1.4, and two for node-v46 and node-v50. (hack alert) In order to have sqlite3 work with my other dependencies I copy the binary found in the Electron-v1.4 folder and put it in both node-v* folders. That way when running in Electron, all dependencies are running the correct binaries even though they are looking for them in the wrong place. (end hack alert)
Conclusion
There is no way I can be sure this has anything to do with the issue you are seeing. But it is worth a shot to see if it fixes your problem. If not then at least I hope I can help someone else experiencing the same issues I ran into.

const INLINE = 'inline'; with npm related commands

Today I was trying to work on Angular2 (template https://akveo.github.io). As per installation guide, I ran following commands.
I have installed Node.js v6.9.1.
npm install --Worked fine.
npm server --Failed with below error.
E:\........\node_modules\script-ext-html-webpack-plugin\index.js:3
const INLINE = 'inline';
^^^^^
SyntaxError: Use of const in strict mode.
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
After many random searches and failing to resolve it, I decided to think about it with a calm head. To me it looks like it is a problem with ES2015/ES6. Package script-ext-html-webpack-plugin uses const variable which is a ES2016 feature. However system is unable to resolve it.
Also this problem can come with any package like hapi, selinium etc. But everything should have same solution I guess.
I have tried many related commands on the installation guide of the website mentioned above but nothing works and ends with same error. I have also many have faced same issue online but nothing concrete is visible as answer.
Could anyone help me out?
Update
Below approach has also fixed many of my colleague's machine who were facing some random errors with nodejs.
This problem is resolved in at least my machine. I am certainly not a person who understand nodejs completely but got it working after some googling. The solution given below may be common to many other issues I guess.
The system I am working has Windows 10 as Operating System and has 64 bit processor.
Go to control panel and uninstall nodejs (just to make sure you do not have traces of any previous install).
Install latest version of nodejs from their website (I installed v6.9.1 for 64 bit processor).
Go to Environment variables for system (just type environmental variables in start menu if using Windows 10) and edit the Path. Delete ‘C:/Program Files (x86)/nodejs’ (as I had installed 64 bit nodejs). This ensures when using command you do not use any other previously installed nodejs.
Start command prompt in Admin mode and navigate to your project and run npm install.
In case you get any/some error, then run npm info graceful-fs -v or npm info graceful-fs whichever runs in your machine.
Then run npm update -g npm.
Then run npm install again and this time it should work.
Run npm start and everything should work fine.
On running website, sometimes we see any other issue and that can be seen from console logs. But good thing is, console logs also tell you the problem. In most cases its related to 32 bit and 64 bit processor due to our recent changes. In my case, I was facing issue with SASS configuration due to 32/64 bit machine and console log asked me to run npm rebuild node-sass to fix the issue.
Go back to command prompt, hit Ctrl+C to stop npm server. Run node rebuild node-sass. Run npm start again and everything should be working.
Hope it helps.

Resources