Gulp running on OSX & Windows - node.js

I'm new with Gulp, I have created my project in windows and installed/configured everything in my gulpfile, everything works fine.
My project is synchronized with Google Drive between my Windows 8 PC and macbook.
But when I run "gulp" command in osx this isn't working
"Error: Cannot find module 'loadash.basevalues'
Node is installed in OSX and on a different project that I created in OSX it is working fine. Am I missing something? Sorry if this is a dumb question, but I can't find anything about this in Google

You should not move node_modules folder between your environments. Package.json file should contain all data and package names for you dependencies.
You can set up free remote git repository on services like github or gitlab, add .gitignore file inside root of your project, specify inside folders to exclude (node_modules obviously) and send it on remote git repository with "git push" command, to "git pull" any updates from your second location.
Remove entire node_modules folder on your OSX and run "npm install" or shorted "npm i". You might want to check if your node and npm versions are matching with "node -v" or "nodejs -v" and "npm -v" commands - if these versions are much different, consider to update your environment.

Related

How to run npm webpack vue project on both Windows and Mac?

I took a Vue 2 online course and it did show (but didn't really explain) how to install node.js, npm and vue. Currently using vue-cli to set up my project using vue init webpack-simple. Problem is I have a Windows desktop and a Mac laptop. I'm using Box cloud on both but I need to have 2 separate folders for the same project. Basically, project-1-windows and project-1-mac.
I can't run npm run dev on the project-1-mac while on Windows 10 and vice versa. The only way I know to run both is to delete the node_modules folder and run npm install. However it takes a while for the files to download. Is there an easier way to do this?
It looks like you want either GitHub/BitBucket/friends or (for much more complex set-ups) Docker.
I will explain only the first (easier) option. To set-up docker, you rather go to its docks.
So, for GitHub/BitBucket/friends way, you need some one-time set-up (you have to do all of this in terminal of your machine. I don't go too deep into details because you may find corresponding docks for each thing easily by googling it).
Install git if needed on both machines. On mac, you just run git --version in terminal. It'll either show the version of installed git or will ask if you want to install git together with other developer tools.
Install brew on Mac, install any of these on Windows. These are just package managers. Use them to install nvm.
Install nvm (it's node version manager, arguably the most convenient way to manage node.js installations) on both machines.
Use nvm to install node.js (npm comes bundled with it) on both machines. That's it! One-time set-up done. Run node -v && npm -v to check that both are installed.
Now, to start each project you would do the following:
Create a repo (which is like a folder but on GitHub/BitBucket server) that you may freely access from any device that has internet connection.
Start project on any of your machines with something like npm init or vue init webpack-simple or whatever you feel comfortable with.
Run git init
When you do changes, commit & push them into your online repo.
Avoid committing files that might be auto-regenerated, they simply don't worth storing.
You may use any npm commands.
When you want to continue working on another machine, simply git clone your existing repo, run npm install and you are done.
Commit changes if needed.
git pull changes to another device if needed

Why is Heroku telling me it cannot find a package.json in my module when I do a heroku push

I created my own npm package from a fork of react-coverflow. It appears to be working fine in my app locally using it this way: "npm install react-coverflow-mod" --save.
I can run my app using "run with debug (F5)" in VsCode and npm start on the client folder to start the React front end.
Then I do an npm run build on the client folder, and it works just fine.
When I do a heroku push it fails everytime with this error:
npm ERR! code ENOLOCAL
npm ERR! Could not install from "../../react-coverflow-mod"
as it does not contain a package.json file.
1. I know there is a package.json in the module because I can install it via "npm install react-coverflow-mod": https://www.npmjs.com/package/react-coverflow-mod
2. The installed module has a package.json file in it
3. My github repo has a package.json in it: https://github.com/leroyvaughan/react-coverflow
I'm not sure how I can fix this. Do I need a package.json to go into the /Dist folder? What is wrong here with Heroku.
It seams like heroku try to install a package from a relative path instead of the published name. That would perfectly explain why you can run locally but not on a production environment.
Open your project and search for the exact string displayed in your log: "../../react-coverflow-mod" and you should be able to find quickly where it is.
If you run on a unix system (don't know about windows) you can do a search using grep:
grep -rnw '/path/to/somewhere/' -e '../../react-coverflow-mod'
Make sure it includes your root folder which contain package.json, and might we wise to ignore node_modules which is always massive.

Access rights for node_modules folder at MacOS/Linux and Windows

I'm developing some nodeJS applications on a mac machine. For testing purpose I'm using Parallels to get a virtual windows machine (win 10).
If I'm running npm install for a project on my mac, I can't run the project on the windows machine, as I'm getting an access denied error for the node_modules folder.
So I deleted the folder an run npm install on the windows machine. With that I can run the app. But then on my mac machine I do get e.g. sh: /Users/project/node_modules/.bin/nodemon: Permission denied.
What can I do to set the correct access rights to the node_modules directory to get the app running on both OS?
That is because the binaries (.bin) compiled in macOS need not necessarily work with windows too.
For your scenario, use YARN. Because YARN offers offline install.
Reference link: https://yarnpkg.com/blog/2016/11/24/offline-mirror/
In either of your systems install YARN.
npm install yarn
Inside your project folder in a cmd or a terminal just type yarn
-Yarn will start resolving your packages.
Once done, create a .yarnrc file by executing the following commands (same for both windows and macOS).
yarn config set yarn-offline-mirror ./npm-packages-offline-cache
yarn config set yarn-offline-mirror-pruning true
A .yarnrc file will be created in your home directory (macOS => ~/.yarnrc || windows => C:\{user}\.yarnrc).
Move that file into your project to make it specific only to your project.
Now do a yarn install -> Results in node_modules folder and a yarn.lock file. Also note that in the home directory under the folder npm-packages-offline-cache you will have all the dependencies in tarball format.
All you have to do is Commit this tarball directory and the yarn.lock to a repository common to both the environments, setup yarn in other environment by repeating the same 1-5 steps.
Finally run yarn install -offline, you will have the dependencies loaded.
Long story, Short! You can't just copy paste node_modules and get it working between windows and unix.
Hope it helps you..

Custom CLI similar to "npm install" that will install libs in folder other than "node_modules"

I understand that "npm install" in NodeJS will actually install libraries into a folder called "node_modules".
I am actually wanting to achieve something similar but to use my own CLI instead (eg using commands like "myproject install" instead of "npm install") and then the libraries (proprietary ES6 source codes from my company's Enterprise Git Repo) will be installed into a specific folder (eg "myown_modules" rather than "node_modules").
Question is, how do I achieve that, assuming that I want dependencies checking as well on the libraries that are going to be installed? Also, how do we control versions using own CLI?
Use this repo and modify it to do what you want.
You need to change the install folder and change the process with the name you want.
NPM repo : https://github.com/npm/npm
OR :
Create a bash script who will do npm install xxxx when you use myscript xxxx, so you can't change the node_modules with this.

Gulp installs outside project root

I've encountered a weird issue when installing Gulp in a new project.
Let's say I have the following path:
c:/development/myproject
When I run npm install gulp in that directory, the node_modules folder actually gets created in
c:/development/node_modules
instead of
c:/development/myproject/node_modules
And all of gulp plugins also get installed in that directory outside my project root.
I also have an earlier project where gulp was already installed before, and when I tried to rerun gulp installation in that project directory it was installed correctly in the project root (for example: c:/development/myolderproject/node_modules), not outside.
I don't think it has anything to do with the case, but the new project is using Laravel 4, while the other one is on Laravel 5.
I don't recall having to set any specific configuration before, so I'm totally confused why it behaves differently.
When you did npm install it found package.json from parent directory and thought it was the package root.
Related docs: https://www.npmjs.org/doc/files/npm-folders.html#more-information
Starting at the $PWD, npm will walk up the folder tree checking for a folder that contains either a package.json file, or a node_modules folder. If such a thing is found, then that is treated as the effective "current directory" for the purpose of running npm commands. (This behavior is inspired by and similar to git's .git-folder seeking logic when running git commands in a working dir.)
If no package root is found, then the current folder is used.
I run Ubuntu 15 and I had a similar issue where gulp was installing the node_module folder somewhere I couldn't find. gulp would say ../../node_modules was the location but it was NOT in my project folder.
I figured out from the link above and some more research I just needed to run npm init to create a project.json in my project folder. gulp was installing the node_modules in another folder because it searches for a project.json file to install the folder node_modules into.
Hope this helps anyone else solve this silly problem.

Resources