Node js - cant install packages on a server - node.js

I want to have grunt on my server, and via hook, i want the server to run a grunt task that will "build" my site.
I installed node on my server, and i installed grunt-cli using this:
$ sudo apt-get update
$ sudo apt-get install nodejs
$ sudo npm install -g grunt-cli
then, i go to my project folder, which is where my package.json and gruntfile.js files are located.
im using npm install and then, i see /node_modules folder but i don't see the packages there.
I don't see any error. Do you know why this happens? perhaps server configuration?
package.json
{
"name": "proj",
"version": "0.1.0",
"private": true,
"devDependencies": {
"angular": "latest",
"angular-animate": "latest",
"angular-ui-router": "latest",
"font-awesome": "^4.5.0",
"grunt": "latest",
"grunt-contrib-clean": "latest"
}
}

With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.
source: https://docs.npmjs.com/cli/install#description
Since you're on a server, I assume, this is a production one and NODE_ENV is set to production. To install both dependencies & devDependencies, run:
NODE_ENV=dev npm install

Related

npm not installing packages and not creating package-lock.json

I created a new Laravel project with laravel new x
changed into that folder with cd x
tried installing the npm packages with npm install
This didn't work like expected.
I just got an Error: Cannot destructure property 'name' of '.for' as it is undefined.
Then I was like yeah lets just add a name to the package so I did
Ran npm install again
After that it installed something and prompted: Installed 1 Package
Instead of installing the specified devDependencies, creating a package-lock and a node_modules folder, it installed a package with the name that i just specified, globally. I knew that because of npm ls -g. So now i dont have any packages installed locally in my folder but a dependency globally that does nothing.
Output of npm ls and npm ls -g:
C:\Users\johnw\AppData\Roaming\npm
└── theNameIJustSpecified#
My package.json looks like this (and was auto-generated by the laravel installer):
{
"name": "myName",
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"axios": "^1.1.2",
"laravel-vite-plugin": "^0.7.2",
"lodash": "^4.17.19",
"postcss": "^8.1.14",
"vite": "^4.0.0"
}
}
npm -v: 9.2.0
node -v: v19.3.0
os: windows 11
Normally this just worked out of the box with the Laravel installer. I just typed npm install and it worked.
I tried reinstalling Node and npm, even used Nvm for Windows without any change.
I tried restarting my pc without any change.
I tried creating the package.json via npm init, didn't change anything other than the output of npm ls -g (added 1.0.0 to the end):
C:\Users\johnw\AppData\Roaming\npm
└── theNameIJustSpecified#1.0.0
Edit: Tried downgrading to npm 8, also didn't work.
Downgrading to 7 works again, but I get warning because of too old version.
I checked other projects (old Laravel projects) and they have the same problem now. I used to work in them for months using npm packages for asset bundling. Now they give me the same error.

Is is possible to install dependancies with single line command?

My Node.js
package.json
has following dependancies
"dependencies": {
"body-parser": "^1.18.3",
"express": "^4.16.4",
"mongoose": "^5.3.10",
"nodemon": "^1.18.5"
},
"devDependencies": {
"eslint": "^5.8.0",
"eslint-config-airbnb-base": "^13.1.0",
"eslint-plugin-import": "^2.14.0"
},
I am new to JS,so I want to know if we can somehow invoke package.json without going for
npm install
for every package.
When you use the command npm install or npm i, it will install all dependencies from your package.json.
As a result you get all the dependencies listed in the package.json from the current folder
You can see the documentation concerning this command here : npm install
Welcome to JS world, I'm fairly new to JS myself but I believe there two possible solutions to your problem:
npm install multiple dependencies
It is possible to install multiple dependencies at the same time with one npm install command, you may find more information that could be helpful in the documentation.
For example:
npm install got koa fs-extra
Here I have installed all 3 of my project dependencies at once.
Pre Populate package.json
You can manually add the package dependencies in the correct format to your package.json file. You might the npm documentation on the package.json file helpful.
You then will need to run:
npm install
This will take the dependencies in the package.json file and install them into the node_modules/ directory.

cross-env/dist/index.js:42 unexpected token }

A little background: I'm developing a Laravel 5 application. I'm developing locally on Windows 7 using Homestead (using Vagrant/VirtualBox) and deploying to an Amazon EC2 instance through CodePipeline.
While trying to get Laravel Mix working locally, I kept running into a cacophony of errors that eventually led me to the solution of installing cross-env globally rather than including it in the devDependencies in package.json. Of course, this also means that my Amazon deployment needed to be updated to that setup as well. None of this is really relevant except to explain that cross-env is installed globally on my deployment, in case that's relevant.
My package.json:
{
"private": true,
"scripts": {
...
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
"axios": "^0.16.2",
"bootstrap-sass": "^3.3.7",
"jquery": "^3.1.1",
"laravel-mix": "^1.0",
"lodash": "^4.17.4",
"vue": "^2.1.10"
}
}
My deployment to AWS fails on npm run production with the following error:
[stderr]/usr/lib/node_modules/cross-env/dist/index.js:42
[stderr] });
[stderr] ^
[stderr]SyntaxError: Unexpected token }
What could be causing this issue? And how can I resolve it? I highly doubt that there's actually a syntax error in cross-env.
I had the same problem and i could fix it by updating node and re-installing npm.
Steps that worked for me:
Update Node using a package manager:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
Then fresh install:
rm -rf node_modules && npm cache clean --force && npm install
Hope it helps
In my case I had to upgrade both nodejs and npm:
wget https://nodejs.org/dist/v6.9.2/node-v6.9.2-linux-x64.tar.xz
tar -C /usr/local --strip-components 1 -xJf node-v6.9.2-linux-x64.tar.xz
Then I run npm install without any errors.

Gulp build does not install dependencies automatically?

I use gulp to build my javascript application. I have some dependencies declared in the package.json file, for example:
"dependencies": {
"flux": "^2.0.1",
"keymirror": "~0.1.0",
"object-assign": "^1.0.0",
"react": "^0.13.1",
"dropzone": "^4.0.1",
"lodash": "^3.6.0"
}
When I run gulp build, it always prompt me some dependency cannot be found unless I manually run npm install lodash for example.
Is there a way to have gulp run npm install automatically?
Run npm install --save-dev command to resolve all dependencies.
Here is link to documentation with --save-dev parameter description: https://docs.npmjs.com/cli/install
You require to have package.json on the root level.
Then once you have to run npm install for all the dependencies with --saveDev(development dependencies) or --save(project level dependencies).
Once this is done, for the next time only run npm install command will install dependent dependencies.
gulp-install would help for your issue. Go to NPM (node package manager) and search for "gulp-install".
The node plugin gulp-install automatically installs packages/dependencies for npm, bower, tsd, and pip. The relative configurations must be found in the gulp file stream.
Example Usage:
In your gulpfile.js:
var install = require("gulp-install");
gulp.src(["./package.json", "./bower.json"])
.pipe(install());

Nothing happen with bower install

I'm trying to setup angular app with yeoman, following this steps: http://yeoman.io/
Everything works fine until I do
grunt test
I got
Chrome 24.0.1312 (Linux) ERROR
Uncaught ReferenceError: angular is not defined
at /var/www/moviz-test/app/scripts/app.js:3
Chrome 24.0.1312 (Linux) ERROR
Uncaught ReferenceError: angular is not defined
at /var/www/moviz-test/app/scripts/controllers/main.js:3
It's because bower install do nothing, I don't have the folder app/bower_components
.bowerrc
{
"directory": "app/bower_components"
}
bower.json
{
"name": "myApp",
"version": "0.0.0",
"dependencies": {
"angular": "~1.0.7",
"json3": "~3.2.4",
"jquery": "~1.9.1",
"bootstrap-sass": "~2.3.1",
"es5-shim": "~2.0.8",
"angular-resource": "~1.0.7",
"angular-cookies": "~1.0.7",
"angular-sanitize": "~1.0.7"
},
"devDependencies": {
"angular-mocks": "~1.0.7",
"angular-scenario": "~1.0.7"
}
}
I've uninstall and reinstall bower and nothing change
bower -v 1.2.3
node -v v0.10.17
This happened to me as well. The reason was that I was following old tutorial that said bower's package file was components.json instead of bower.json. So bower was looking for later and as it couldn't find file it would just say nothing (it should actually show warning or error). When I renamed file to bower.json it all worked.
I couldn't install newest ember package because bower install did nothing, but:
cd bower_components
rm -rf package-name
now bower install
helped.

Resources