npm install is not installing grunt js from dependencies - node.js

I am trying to automatic all the package installations automatic for developers. So I have both package.json and grunt file in the same directory. I want to do npm install first so that all dependencies will be installed and when developer executes grunt on command line things will be ready. May I know why it is not working. The other thing is may I know the difference between dependency and devdependencies.
{
"name": "TestProject",
"version": "0.1.0",
"description": "this project is for test",
"main": "index.js",
"dependencies": {
"grunt": "~0.4.2",
"grunt-contrib-uglify": "~0.2.7",
"uglify-js": "~2.4.3",
"grunt-contrib-watch":"~0.5.3",
"grunt-contrib-jshint": "~0.7.2",
"qunit": "~1.11.0"
},
"devDependencies": {
"grunt": "~0.4.2",
"qunit": "~1.11.0",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-nodeunit": "~0.2.0",
"grunt-contrib-uglify": "~0.2.2",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-watch":"~0.5.3"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause"
}

You are probably missing the command-line utility for Grunt.
That can be installed in your shell, using
npm install -g grunt-cli
The CLI is distributed independently from the grunt package or the grunt- plugins. You should include instructions to install grunt-cli globally in the same dev environment setup documentation where you indicate how to set up node, npm, bower, or the like.
Update
If you are so adamant about installing grunt-cli on npm install, I guess one option might be using npm scripts.
Include in your package.json (note: untested)
{
"postinstall": "npm i -g grunt-cli"
}
I'd discourage this, though. Just install them by hand.

Related

How to fix "Cannot Find Module node_sqlite3.node" while it works in production but throws this error on publish

I am Stuck in a problem, actually the problem is "my project works fine in production build while i do 'electron .' but when i publish the app with electron-packager and try to run it, it say 'Cannot Find Module node_sqlite3.node',
I tried installing sqlite3 using npm install --save sqlite3 --build-from source but no luck
Here is my Dev Env
node -v 10.15.3
npm -v 6.4.1
electron 4.1.3
sqlite3 4.0.6
I say again it works on electron . but doesn't work when I publish the app with electron-packager
i execute the following command for publishing
"publish": "electron-packager . Order-MGT --platform=win32 --arch=ia32 --prune=true --out=dist --ignore=.gitignore --ignore=README.md"
package.json
{
"name": "sample17",
"version": "2.1.0",
"description": " Inventory Management System",
"main": "main.js",
"scripts": {
"start": "electron .",
"rebuild": "electron-rebuild -f -w sqlite3",
"publish": "electron-packager . Order-MGT --platform=win32 --arch=ia32 --
prune=true --out=dist --ignore=.gitignore --ignore=README.md --version-
string.CompanyName=SaqiXPRO --version-string.FileDescription=SaqiXPRO"
},
"dependencies": {
"ejs-electron": "^2.0.3",
"node-gyp": "^3.8.0",
"nodemailer": "^5.1.1",
"sqlite3": "^4.0.6"
},
"author": "SaqiXPRO",
"license": "MIT",
"devDependencies": {
"electron": "^4.1.3",
"electron-packager": "^13.1.1",
"electron-rebuild": "^1.8.4"
}
}
I want to make it working as it does on electron . but i can't quite understand what to do please help
I had solved the problem by the doing the following
I installed C++ Build Tools 2015 or later and the issue was resolved

Webpack not working in my node.js project. fsevents

I'm currently trying to implement this tutorial:
https://www.typescriptlang.org/docs/handbook/react-&-webpack.html
I'm supposed to install react and react-dom and also webpack + typescript + awesome-typescript-loader + source-map-loader, and that's what I did. I also installed webpack-cli accordingly to instructions that I got from the command line.
I installed all of them locally (the react and react-dom as PROD and the rest as DEV dependencies).Currently I don't have any packages installed globally.
After this, that's my package.json file:
{
"name": "reactandwebpack-tutorial",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"awesome-typescript-loader": "^5.2.0",
"source-map-loader": "^0.2.3",
"typescript": "^2.7.2",
"webpack": "^4.16.4",
"webpack-cli": "^3.1.0"
},
"dependencies": {
"#types/react": "^16.4.7",
"#types/react-dom": "^16.0.6",
"react": "^16.4.2",
"react-dom": "^16.4.2"
}
}
At this point, when I run npm ls I get a bunch of errors, because of some optional dependency of webpack that apparently is missing (all the errors in the tree are inside webpack and below fsevents as following):
webpack#4.16.4
(...)watchpack#1.6.0
(...)chokidar#2.0.4
(...)fsevents#1.2.4 -> UNMET OPTIONAL DEPENDENCY
And everything below fsevents is also marked with UNMET DEPENDENCY
And when I run webpack command, I get a "webpack not recognized error".
Anyone can help? I've been trying to wrap my head around this for a while.
PS:
Npm -v 5.6.0
Node -v 8.11.3 //(that's what I get from the terminal,
//VSCode "About" tells me something different, I don't know why).
Using Visual Code
Version 1.24.0
Date 2018-06-06T17:35:40.560Z
Shell 1.7.12
Renderer 58.0.3029.110
Node 7.9.0
Architecture x64
The reason is because it was not linked to your env. When you install something globally, you have access to it everywhere, hence it works just by doing webpack. Since you installed everything locally, the binaries are located inside node_modules/.bin.
You have two options when you install something locallly.
Use npm scripts (npm run build, watch... whatever).
./node_modules/.bin/moduleName --flags
It is easier to create a npm script and add all the commands there.
SOLVED
Not sure the reason but it had something to do with the ./bin folder with the webpack-cli "ambient variable" not being available (I don't know it that would be the most accurate description).
When I try to run webpack, I get "not recognized error".
But when I run nodemodules\.bin\webpack-cli it works normally.
Everything is installed locally.
I can also run it with options, like nodemodules\.bin\webpack-cli --help
If you run "webpack", The CLI will find global webpack with is installed by (npm install webpack -g). To use webpack from local project. you should it to npm script.
package.json
{
"script": {
"start": "webpack"
}
}
By doing this, you can run npm start to run webpack.

NPM doesn't install dependencies that need build

My package.json file looks like the following :
{
"name": "anna-backend",
"version": "1.0.3",
"description": "Backend for ANNA intranet",
"main": "app.js",
"author": "IpsaOne DevTeam",
"private": true,
"license": "ISC",
"dependencies": {
"async": "^2.6.0",
"bcrypt": "^1.0.3",
"body-parser": "^1.17.2",
"mmmagic": "^0.4.6",
[...]
}
}
When I run npm install in the folder, everything installs well except the dependencies that require building via node-gyp (like bcrypt, mmmagic) and I have to install them manually by typing npm install mmmagic. Otherwise, they're just not installed and my application doesn't start.
Is it expected behaviour ? Can I do anything about it ?
mmmagic module has issues on install
https://github.com/mscdex/mmmagic/issues/111
try install at last version 0.5.0

Only install packages that are included in the package.json

I just want to install only packages that are included in the packages.json. But when I run npm install, over 800 packages are suddenly installed. Is there a specific command to realize this or is my package.json (see below) wrong?
{
"name": "test",
"version": "1.0.0",
"description": "test",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "test",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.13.0",
"gulp": "^3.9.1",
"gulp-autoprefixer": "^5.0.0",
"gulp-concat": "^2.6.0",
"gulp-cssnano": "^2.1.2",
"gulp-htmlmin": "^4.0.0",
"gulp-imagemin": "^4.1.0",
"gulp-install": "^1.1.0",
"gulp-jade": "^1.1.0",
"gulp-jsonminify": "^1.0.0",
"gulp-ng-annotate": "^2.0.0",
"gulp-sass": "^4.0.1",
"gulp-uglify": "^3.0.0"
},
"dependencies": {
"critical": "^1.2.2",
"imagemin-pngquant": "^5.0.0"
}
}
npm install uses package.json to install packages you want AND their own dependencies. So you haven't choice unless you want broken packages ? In that case you could manually uninstall packages you don't want.
In this case when u install this packages the dependencies of that particular packages has also been installed.
Like if u install critical module then =>
bluebird
chalk
cheerio
clean-css
cli
debug
filter-css
fs-extra ... etc
has also been installed, that's the case in here
I am not sure why would that be happening, whenever we run npm install it picks up the package.json and installs packages defined in it including the transitive dependencies. By looking at your package.json there should not be 800 of them.unless you have multiple package.json linked up with each other.
I would recommend to copy package.json to a different directory and clear cached in modules and
run npm install --log-level=verbose
this should give in the details for the rest packages being called up.

npm install does not install the dependencies of individual node modules into the respective node modules folders

npm install was installing node modules correctly until recently when I ran into a bug. Now, npm install does not install the dependencies of individual node modules into the respective node modules folders.
See screenshot for what I mean.
The finder window at the forefront shows the correct npm install before the bug. npm install express would download and put the files in correct folders. The accepts folder is a node module of express and has its own node modules, mime types and negotiator.
Now, the accepts folder and its own node modules sit out at the same level as express folder. As seen in the finder window in the back.
This is causing me not to be able to upload to heroku.
Please advise on how to fix.
Here's my package.json
{
"name": "node-muse-examples-webgui",
"version": "0.1.0",
"description": "An example on how to use the node-muse module in a web interface.",
"main": "index.js",
"engines": {
"node": "7.2.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://github.com/ShaPOC/node-muse/tree/master/examples/webgui"
},
"author": "Jimmy Aupperlee <j.aup.gt#gmail.com>",
"license": "GPLv3",
"dependencies": {
"body-parser": "^1.15.2",
"express": "^4.14.0",
"leapjs": "^0.6.4",
"mongodb": "^2.2.7",
"node-muse": "^0.1.0",
"socket.io": "^1.3.5"
}
}
That behavior is not a bug, it actually is a new behavior introduced with npm#3.
That normally should not cause any conflict or problems, but if it does in your case try to install it with
npm install --legacy-bundling
instead, so delete the whole node_modules folder and reinstall it with that command.

Resources