Node-sass build issue with Docker - node.js

I am working in Docker to containerize the Angular 5 application. This app uses node-sass 4.7.2. The application works fine in the Windows environment. During "npm install", it downloads the node-sass or builds the same using the sass-library-path defined in .npmrc file.
But, there are a lot of issues during the docker image creation process. It automatically tries to download binding.node file from https://github.com/sass/node-sass/releases/download/v4.7.2/linux-x64-72_binding.node
But, there is no release for linux-x64-72. So, it downloads a dummy file(sized about 4KB) and throws "invalid ELF header" error.
If I specify some valid URL in sass-binary-path(https://github.com/sass/node-sass/releases/download/v4.7.2/linux-x64-59_binding.node), it throws "no module found" error.
I tried with npm rebuild node-sass as well. I saw a lot of answers from the internet as well. Many of the answers suggested me to copy node-modules from the local environment. You know, this is never an option with Docker. I can't ask developers to commit node-modules also in the repository.
Is there any way to resolve this issue? or Is there any simple solution to solve it in the angular application like not using node-sass?

There was a node sass version specified in the package.json. For the corresponding node-sass version, there is no library available for the os linux-x64-72_binding.node.
So, I upgraded the node-sass version in the package.json for which the Linux library was available.
Then, it downloaded the file without any issues.

Related

NPM not installing node module

I have an angular project that comes with a package.json file and all the dependencies listed within, but each time I run "npm install", in the terminal, the packages appear to be downloading properly and a node module folder is created in my root folder, but at a certain stage the installation stops without an error message and the generated node module folder disappear from my project. please what do I do?
I can't reproduce your situation, somehow this may not fitable for you.
But I suggest re-install node.js to make sure npm install work correctly.
This link will help to find what version of node.js for you, based on you angular version.
Compatibility list for Angular/Angular-CLI and Node.js
Also, It would be good to manage node.js via NVM(Node Version Manager).

creating angular 8 project on windows 10 creates additional files

Up until a few days ago I have been using an Ubuntu virtual machine as my development environment for Angular and other related projects due to school, however I decided to switch over to windows since I already had node installed along with git and other development tools.
The issue I'm having is when I create an Angular 8 project using the ng new my-app command, additional files are being created in the root directory which never happened while I was using Ubuntu. The files that are being created are Command files (.cmd) and Powershell files (.ps1), along with files with no extension.
These are just some of the files that are created:
Angular 8 project files on windows
If I compare with the file structure of the projects created in Ubuntu (which are the typical angular.json, tslint, etc), I can delete the unnecessary files and the angular app still works. However, whenever I run npm install to reinstall the packages due to some error, these excess files are added again and I have to delete them every time.
I have tried uninstalling angular/cli and clearing cache using npm cache clean --force and installing angular/cli again but the problem persists. I have also tried removing node and installing it again to no avail.
I'm fairly new to angular and node.js, with only a few months experience from school projects, so I'm currently trying to learn more. I've tried searching using different terms but nobody seems to have encountered a similar problem. Any help is much appreciated.
These are the files that are found in the node_modules/.bin subfolder after npm install is done.
There is something wrong with your npm install. I would recommend uninstalling node, and making sure everything is removed (path variables, files in your user folder) and then reinstall it.

How to zip a nodejs server app?

I have to create a zip file of my whole nodejs server app.
I should be able to unzip it and run it, without installing dependencies and apps.
It should not be a binary file.
The dependencies should be flattened.
How to do this thing ?
Generally, a Node.js app has its dependencies installed in the node_modules directory in the project root.
So, after running npm install (or npm install --production), you should be able to zip up the project directory and that should be all you need.
If any of your dependencies in node_modules are native addons, then you will not be able to install them on a different architecture or OS. If there are native addons, you will also want to make sure your target machine has the same version of node installed as the machine where you created the zip file. (It's a good idea anyway, if you can, to make sure the node version on the target machine is the same as the source machine.)
One obvious requirement of the target host if you do as I describe above is that node is already installed there. Not sure if that's OK for your use case or not, but sounds like it probably is?
Thank you, all of you for your help.
I got the solution for my question.
I am using npm pack to pack the nodejs app.
To pack nodejs app with some dependencies like morgan, express we need to use npm bundle it helps to include the other module required for node js app.
With this, we don't need to perform npm install.
We just have to install bundle and then include bundleDependencies field including the name of required module in package.json.
And then perform then run the command npm pack. It will create a tar file just copy this file in other folder and uncompress it and run the server starting file.
The place where you are going to run the nodejs file, there nodejs app should be installed
I think you might be looking for this: https://github.com/nexe/nexe
Nexe is a command-line utility that compiles your Node.js application into a single executable file.

Error with 'babel-runtime' while trying to serve a Meteor app

I have recently been getting off the ground with Meteor and React. I followed the tutorial on the Meteor website with no problem.
Then I tried creating another project, trying to follow another tutorial (for an older version of Meteor). Somewhere along the line, Meteor started throwing up obscure errors. After trying to start fresh again, I ended up reinstalling Meteor and it stopped complaining.
However, I'm getting the same problems, again. Specifically, after creating a brand new project:
meteor create myproject
cd myproject
meteor
The server throws up the following error:
[...]
W20161109-03:53:42.862(1)? (STDERR) Error: The babel-runtime npm package could not be found in your node_modules
W20161109-03:53:42.862(1)? (STDERR) directory. Please run the following command to install it:
W20161109-03:53:42.863(1)? (STDERR)
W20161109-03:53:42.863(1)? (STDERR) meteor npm install --save babel-runtime
[...]
I do what I'm told and attempt to install babel-runtime package. The server manages to successfully get off the ground, but it then throws up the following error at run-time:
Uncaught Error: Cannot find module 'babel-runtime/helpers/slicedToArray'
at Function.require.resolve
This is all still working off a freshly created project, with no extra packages installed or code changed. I have tried looking online for solutions but, while there are lots of references to bugs that have been fixed, I haven't found anything. A couple of (questions)[Babel - Error: Cannot find module 'babel-runtime/helpers/typeof' on StackOverflow have suggested the following:
Reinstalling the NPM modules
rm -rf node_modules
meteor npm install
Updating NPM
meteor npm update -g npm
I am using Meteor 1.4.2, NPM 3.10.9, Ubuntu 16.04.1.
I was having the same issue. After a little digging, found this: https://github.com/meteor/meteor/issues/8019
* Installing the `babel-runtime` npm package in your application
`node_modules` directory is now required for most Babel-transformed code
to work, as the Meteor `babel-runtime` package no longer attempts to
provide custom implementations of Babel helper functions.
Consider trying it out by using the latest release candidate (not officially released yet):
meteor update --release 1.4.2.1-rc.1
And then:
meteor npm install --save babel-runtime
After upgrading to 1.4.2.1-rc.1 (and then subsequently upgrading to 1.4.2.1 this morning 11/9), the error was resolved.
Try adding package.json file inside your project directory and then run
meteor
npm install --save babel-runtime
in the command line.
You may have whitespace in your project name. All that you have to do is create another project without whitespace in the name. I know that it's quite difficult to detect the cause from the error message, but it is what it is.
I recently faced this issue with meteor 1.11.1 and the solutions here did not work. Turns out I had whitespaces in my project name (Ghughu Server V2) and all I had to do is create another one without the spaces (GhughuServerV2).
P.S. It works fine even if you have whitespace in the path to your project, you just can't have whitespace in the project name. Also, just renaming the directory doesn't work. Either you have to create a brand new project or change some configuration inside (which seems impractical if you're working in a newly created project).

Meteor 0.9.0 bundle and deploy throw errors

I upgraded to Meteor 0.9.0 today. I use meteor bundle filename to bundle my application and upload to AWS. When I try to start it on AWS, I get
wrong ELF class: ELFCLASS32
This is a known problem with fibers/bcrypt, so I used to go to bundle/programs/server/node_modules, remove the fibers and bcrypt folders and reinstalling them (npm install).
However, currently the node_modules directory does not exist anymore... When I am trying to start nodejs I get
Error: Cannot find module 'underscore'
I tried to manually add the modules with npm install, and even got the server to eventually run, but the client didn't load and the console error was about
Spacebars undefined
(I don't have the exact Spacebar issue)
I know that Meteor 0.9.0 is very new, but if you have advice I would really appreciate it!
You don't need to remove any folders, simply do this in the bundle directory (output of the untarred meteor bundle):
cd bundle
cd programs/server
npm install
Meteor 0.9.0 makes sure it puts up all the node_modules which don't contain binaries, and creates a package.json for npm install for both bcrypt and fibers
Since you've removed the npm modules in node_modules you may have to recreate the bundle from scratch to get them back.
For the Spacebars undefined issue its very likely that you have a package in your project that is not compatible with Meteor 0.9.0. You can find out which one it is by checking your server logs. Though it is not compatible, your app will still run.
This may be boostrap-3, though it may not be. If it is you can meteor remove mrt:bootstrap-3 and meteor add mizzao:bootstrap-3.
Akshat, you are a lifesaver! Based on your answer I eventually managed to figure it out! For the benefit of others, I want to document what eventually worked:
First, I had to manually remove all the old packages from my Meteor project (seems that it didn't do it automatically). In particular, I removed
iron-router
which was the pre-Meteor 0.9 version and installed
iron:router
which is the post-Meteor 0.9 version. (I had to do a similar process of removing and adding different packages for 2-3 other packages too).
Then, once I bundled and unpacked on AWS, I did what Akshat said about npm install in bundle/programs/server. In addition, I had to manually remove the original bctypt by deleting the folder
bundle/programs/server/npm/npm-bcrypt
as otherwise I got an ELS error
If you're getting this error with Meteor-Up. Updating the package should fix it.
npm update mup -g

Resources