gulp permission and local install without the json file - json

As it says on the gulp io to install gulp globally you need to run
npm i -g gulp
which will return an EACCES error so you will use sudo in front of the command. Now I go into my new project directory that I want to install gulp in. As they say on the page to install it into your project folder you can use this command
npm i --save-dev gulp
if I do so it returns an EACCES error, which means I will need to use sudo again which I cannot quite get as I only want to install it in a local directory. If I do so it installs node_modules folder with path
gulp#3.9.0 ../../node_modules/gulp
Which means it is installed in my root directory and not the directory I wanted it to install it in. To fix it I can run
npm init
saying yes to everything and then
sudo npm install --save-dev gulp
Which will put node_modules into my project folder
My question is what prevents gulp installation into my project folder be as simple as it is in the gulp instruction? And what can I do to prevent this from happening in the future? I have researched this and people seem to get gulp running without the package.json file which is not a big deal but one more step if you want to jump start on something.

Related

Hexo init fails on Windows

I am trying to initialize a Hexo site on my Windows 10 PC. I have Node 9.9.0 installed as well as git 2.16.2.windows.1.
I have run npm install hexo-cli -g and it installs fine. I then go about the steps listed to create and initialize a site (hexo init test-site) and get the following errors.
I've tried a fresh install of node and git, running npm install a-sync-waterfall -g, and adding a file to node_modules called .a-sync-waterfall.DELETE; but hexo init still fails. Manually running npm install also gives me the same error.
Any ideas? Thanks.
Windows and NPM are not the most stable together. I've found Yarn to much more stable.
Try one of these two things:
Use Yarn
Delete node_modules folder, clear the NPM global cache, attempt a hexo init
del node_modules
npm cache clear --force
hexo init test-site

Does Webpack install -g, automatically install to nodeJS's package.json? Or is this only for local installs?

Does Webpack install -g, automatically install to nodeJS's package.json? Or is this only for local installs?
So I'm tired of trying to find workarounds for require() is not defined. Meaning I would need a module loader for my project to include modules client side. Well, I've downloaded the famous 'webpack' module loader, globally
npm install -g webpack
and I noticed it didn't install to "devDependencies" in my package.json file. But I also install webpack-dev-server, but locally,
npm install webpack-dev-server --save-dev
and it was saved into my package.json. Was this saved because I used --save-dev or because I installed locally?
I'm getting an error stating my webpack module I downloaded doesn't have a configuration file, so I'm assuming I install webpack wrong, and maybe it shouldn't have been installed globally. Please help with the understanding of globally and locally, as well as why this -g webpack install didnt get saved to the package.json?
The command npm install --gloabl will install a package in global scope and make it's bin command available to you globally. This has nothing to do with the folder or project your are in right now. That means a global install will not leave anything in any package.json files.
Learn more about npm install: https://docs.npmjs.com/cli/install
npm install -g webpack will save your files in your OS file system.
npm install webpack-dev-server --save-dev will save your package in your project directory inside a folder called node_modules.
The later one will make an entry in package.json file so that next time you can install all dependdencies with just npm install command. This command installs all your packages listed in package.json.
Missing Config file: Its looking for a file called webpack.config.js. More info can be found here: https://webpack.js.org/configuration/

local gulp not found after installing globally and locally

I have installed gulp both globally
sudo npm install --global gulp-cli
and locally
npm install --save-dev gulp
/usr/local/bin/gulp exists, and ./node_modules/gulp and ./node_modules/gulp-cli exist.
When I try to run gulp on the command line, I get the common error
$ gulp
[00:55:43] Local gulp not found in ~/dev/myProj/play-java-seed
[00:55:43] Try running: npm install gulp
One thing that I noticed is that if I run gulp in some random directory (~/foo), the error message is that the local gulp is not found in that directory. If I run it from the correct directory (~/dev/myProj/play-java-seed/ui) then the error references the parent directory.
There is in fact no gulp installed in the directory in the error message; it is installed on directory lower.
/usr/local/bin/gulp is a symlink to a file with these contents:
#!/usr/bin/env node
'use strict';
require('../')();
Is the .. in that file correct? It seems strange, but I have not looked at it closely before.
If the OS matters, I am running 32 bit Ubuntu 16.04.
devDependencies in my package.json includes both gulp and gulp-cli
Rico Kahler had the correct answer in his comment.
When I looked at the machine (instead of going off of my memory), I saw that the gulp file was one directory higher than it should have been.
The error message did have a clue toward this: it gave the directory holding the gulpfile, not the current directory.

npm recursive install bower dependencies

I have multiple node modules developed by myself stored on a private gitlab server. In my Project, i install those modules with bower, so my Project structure Looks like this:
appname
bower_components
module1
...
package.json
module2
...
node_modules
...
package.json
When i call npm install only the dependencies from the package.json file located in the Folder "appname" will be installed. The Problem is, that my modules, which i install with bower, also have dependencies, which are not listed in the package.json in the root Folder. How can i install those dependencies without installing them globally? It should by something like npm install bower_components\module1. I also tried to use the command line Option --prefix but it only copies the Folder inside the node_modules Folder.
Thanks for your help

Gulp not installed globally?

I've installed Gulp like this:
npm install gulp -g
When I try gulp -v I get this:
[16:19:03] CLI version 3.9.1
But when I try to use gulp in my project by running gulp enter code here I receive:
[16:20:40] Local gulp not found in ~/Code/gulp
[16:20:40] Try running: npm install gulp
What is wrong?
Gulp requires two parts to work in any project:
the gulp object that has the 5 functions attached, (src,dest, watch, run, task). this is installed locally for a project, as well as all the plugins necessary, because it is included in your taskfiles such as gulpfile.js. Its a locally imported module.
npm install --save-dev gulp
the gulp-cli, because this is a command line utility, that can be called from anywhere on your computer. Its a globally accessible cli command. You console needs to be able to see it. You do not import this.
npm install -g --save gulp-cli
you can see more here:
https://www.npmjs.com/package/gulp-cli/tutorial
You have to install gulp inside your project:
npm install --save-dev gulp