This time I am trying to use a npm web3 package in laravel 5.2 project. I am completely new using npm and that too inside laravel.
So far I have below things in my package.json file -
{
"private": true,
"devDependencies": {
"gulp": "^3.9.1"
},
"dependencies": {
"bootstrap-sass": "^3.0.0",
"laravel-elixir": "^2.0.0",
"web3": "^1.0.0-beta.36"
}
}
When I do npm install all the node dependencies are installed in node_modules inside root directory. Now I am trying to figure out how this packages can be bought in use inside public/assets/js/app.js file.
Do I also have to make node services running to use this packages?
npm version: 6.4.1
node version: v8.11.4
Your help is much appreciated.
Updated question - 10th Sep 2018
Downgraded my node package to 6.0 due to overcome few issues with 8.0 I was facing.
node version: v6.0.0
npm version: 3.8.6
New package.json:
{
"private": true,
"scripts": {
"prod": "gulp --production",
"dev": "gulp watch"
},
"devDependencies": {
"#types/node": "^10.9.4",
"gulp": "^3.9.1",
"laravel-elixir-rollup": "^0.3.3",
"laravel-elixir-webpack": "^1.0.1",
"require-dir": "^0.3.2"
},
"dependencies": {
"bootstrap-sass": "^3.0.0",
"laravel-elixir": "^5.0.0",
"web3": "^1.0.0-beta.36"
}
}
New gulpfile.json:
var elixir = require('laravel-elixir');
var path = require('path');
require('laravel-elixir-webpack');
elixir(function(mix) {
mix.webpack(
'./node_modules/web3/src/index.js',
'./public/js/web3-compiled.js'
);
});
When I run npm run dev in console, it stops finishes as below -
[digvijay#Digvijays-MacBook-Air:/var/www/html/estatebaron$ npm run dev
> # dev /private/var/www/html/estatebaron
> gulp watch
node_modules/nan
[17:10:07] Using gulpfile /private/var/www/html/estatebaron/gulpfile.js
[17:10:07] Starting 'watch'...
[17:10:07] Finished 'watch' after 18 ms
What I am expecting here is a js file name web3-compiled.js created in public/js directory, but that does not happen now. Am I missing anything here.
If you are using default laravel 5.2 configuration you're probably missing some lines in package.json see this
So to make it work run npm run dev, but make sure to configure your gulp correctly with gulpfile.js. Read more about this in the https://laravel.com/docs/5.3/elixir and https://github.com/gulpjs/gulp/tree/v3.9.1/docs
Related
I am trying to run an express app that I installed using express --view pug urltracker. I also executed npm install to install all dependencies.
When I start it on my laptop localhost using DEBUG=urltracker:* && npm start
it perfectly starts on localhost:3000 and my app runs smoothly but when I install it on centos 7 server, the same gets stuck at [nodemon] starting `node ./bin/www and nothing happens afterwards.
I tried running it like this as well DEBUG=backend ./bin/www but it says -bash: ./bin/www: Permission denied OR sudo: ./bin/www: command not found
I can execute a normal file like node app.js and it works fine but when it comes to running it as server, it doesn't work.
Here's my package.json
{
"name": "urltracker",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "nodemon ./bin/www"
},
"dependencies": {
"body-parser": "~1.18.2",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"express": "~4.15.5",
"morgan": "~1.9.0",
"pug": "2.0.0-beta11",
"serve-favicon": "~2.4.5",
"puppeteer": "^1.6.2",
"puppeteer-select": "^1.0.3"
},
"devDependencies": {
"eslint-plugin-mocha": "^4.11.0",
"file-system": "^2.2.2",
"jest": "^21.2.1",
"js-comments": "^0.5.4",
"lodash": "^4.17.13"
}
}
I also tried it with running node supervisor using supervisor ./bin/www
but it says
Starting child process with 'node ./bin/www'
Watching directory '/home/admin/web/example.com/node/projects' for changes.
Press rs for restarting the process.
I also tried changing the port to 3001 in ./bin/www like this - server.listen('3001', '0.0.0.0');
but nothing works. Help.
Nodemon is not listed in your dependencies list in package.json and on the centos server nodemon is not present.
Please add the nodemon dependency in the package.json and then run npm i
or change the start script from "start": "nodemon ./bin/www" to "start": "node ./bin/www"
I am using nsp to scan for vulnerabilities. I see a strange behavior.
In scripts, dependency, devDependency section I have the following content
{
"scripts": {
"security-scan:nsp": "nsp check --threshold 10 --reporter json"
},
"dependencies": {
"joi": "10.x",
"dotenv": "4.0.0",
"nsp": "3.2.1"
},
"devDependencies": {
"lab": "14.x",
"code": "4.x",
"eslint": "4.1.1",
"eslint-plugin-import": "2.7.0"
}
}
If I run npm run security-scan:nsp i am getting some vulnerability but now if I move the nsp from dependency to devDependency and run npm run security-scan:nsp i dont get any vulnerability.Can anyone help me out here.
Nsp doesn't scan Dev dependencies. The new npm audit command does and it uses the same database of vulnerabilities, but doesn't have any of the formatting options of nsp.
I am trying to deploy a Sails.js app to Bluemix and we are getting the following error during the deploy stage in the toolchain on Bluemix (When the CF PUSH command is called):
npm ERR! Cannot read property 'pause' of undefined
I understand the trace goes to the npm-error.log file, however, I haven't been able to get to it as we cannot ssh in to see whats in the file as the application is in its "off" state after a bad deploy.
This same code was successfully deployed with both Cf push {app name}} and through a simple build and deploy toolchain in Bluemix just 8 days ago.
In the build stage I can run Npm install and npm update just fine. However, it seems to do this again in the deploy stage regardless and it fails. Here is some detail on this failure
NODE_ENV=production
NPM_CONFIG_LOGLEVEL=error
NPM_CONFIG_PRODUCTION=true
Visit http://docs.cloudfoundry.org/buildpacks/node/index.html#vendoring
NODE_HOME=/tmp/app/.cloudfoundry/0/node
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
Restoring cache
Loading 3 from cacheDirectories (default):
- .npm
- .cache/yarn (not cached - skipping)
- bower_components (not cached - skipping)
Installing node modules (package.json) Building dependencies
sails#0.12.13 preinstall /tmp/app/node_modules/sails
node ./lib/preinstall_npmcheck.js
Sails.js Installation: Checking npm-version successful
npm ERR! Cannot read property 'pause' of undefined
npm ERR! /tmp/app/.npm/_logs/2017-09-09T17_02_48_660Z-debug.log
**ERROR** Unable to build dependencies: exit status 1
Failed to compile droplet
Exit status 223
Staging failed: Exited with status 223
Destroying container
npm ERR! A complete log of this run can be found in:
Successfully destroyed container
Package.json file
{
"name": "myApp",
"private": true,
"version": "0.0.1",
"description": "Stuff my app does",
"keywords": [
"Cool Apps"
],
"dependencies": {
"bcryptjs": "^2.4.3",
"cacheman": "^2.2.1",
"ejs": "2.3.4",
"elasticsearch": "^13.0.0-rc2",
"find-remove": "^1.0.1",
"fs": "0.0.1-security",
"grunt": "1.0.1",
"grunt-contrib-clean": "1.0.0",
"grunt-contrib-coffee": "1.0.0",
"grunt-contrib-concat": "1.0.1",
"grunt-contrib-copy": "1.0.0",
"grunt-contrib-cssmin": "1.0.1",
"grunt-contrib-jst": "1.0.0",
"grunt-contrib-less": "1.3.0",
"grunt-contrib-uglify": "1.0.1",
"grunt-contrib-watch": "1.0.0",
"grunt-sails-linker": "~0.10.1",
"grunt-sync": "0.5.2",
"include-all": "^1.0.0",
"jsonwebtoken": "^7.3.0",
"moment": "^2.18.1",
"moment-timezone": "^0.5.13",
"passport": "^0.2.x",
"passport-http-bearer": "^1.0.1",
"passport-idaas-openidconnect": "^1.1.0",
"passport-local": "^1.0.0",
"rc": "1.0.1",
"request": "^2.81.0",
"request-promise": "^4.2.0",
"sails": "~0.12.13",
"sails-disk": "~0.10.9",
"sails-mongo": "^0.12.2",
"stream": "0.0.2",
"uuid-1345": "^0.99.6",
"validator": "^7.0.0",
"natural-sort": "^1.0.0"
},
"scripts": {
"start": "node app.js"
},
"engines": {
"node": "^8.0.x",
"npm": "^5.0.x"
},
"main": "app.js",
"author": "Scott N",
"license": ""
}
Things I've tried so far.
-change node versions
-changed npm versions
-change dependencies versions to include the ^ prefix
-removed all dependencies but Sails in the package.json file
So Sails.js and the Nodebuildpack/Bluemix aren't playing well with each other.
Any help would be appreciated.
Thank you
It happens to me just the same. and I've to roll back the prev version of npm: 5.3.0 and it's working now. (BTW: macOS)
The error only happens when I update my npm version like this:
Update available 5.3.0 → 5.4.1
Run npm i -g npm to update
The best way to handle it is to update your package.json to use engines like so
"description": "a Sails application",
"keywords": [],
"engines": {
"node": "6.10.1",
"npm": "5.3.0"
},
Got this issue while trying to push to heroku which seems to be the npm version specified by #m-t, and also specifying the versions like above makes ibm bluemix pick it up as default node engine instead of using the latest stable version.
And don't forget to always specify your node and npm versions directly, instead of adding tilde or caret, this just to be safe. check https://stackoverflow.com/a/22345808/5836034 for more about tilde and caret
you can still check #sai-vennam answer here for more info
So I rolled back the sails version in the package.json file from 0.12 to 0.11 and it deployed fine. So CF PUSH and the newest sails version are not getting along on Bluemix. This was using Node 8.0 and NPM version ^5.0.x
I'm trying to deploy a Node app to Heroku, but I'm having an issue successfully running browserify when the app is deployed.
When I'm running locally, I browserify my script with npm run bundle like so (from package.json):
"bundle": "./node_modules/browserify/bin/cmd.js build/main.js -o public/scripts/bundle.js
which browserifies the script in build/main.js and puts it into public/scripts/bundle.js.
For deploying to Heroku, I added
"postinstall": "npm run bundle"
However, when I deploy, I get the following error:
Error: ENOENT: no such file or directory, open 'public/scripts/bundle.js.tmp-browserify-59309133185877094263'
Well, that's correct, that file shouldn't exist... yet. When I run npm run bundle locally, I do see that file briefly pop into existence, but then it is quickly removed and I'm left with a nice updated bundle.js.
I read through Heroku's docs on this, but I'm miffed... can anyone clarify how to get through this?
For reference, here are the relevant parts of my package.json:
"scripts": {
"bundle": "./node_modules/browserify/bin/cmd.js build/main.js -o public/scripts/bundle.js",
"postinstall": "npm run bundle"
},
"dependencies": {
"body-parser": "^1.17.1",
"browserify": "^14.1.0",
"ejs": "^2.5.6",
"express": "^4.15.2",
"jquery": "^3.2.1",
"path": "^0.12.7",
"superagent": "^3.5.2"
},
"devDependencies": {},
"engines": {
"node": "6.8.1",
"npm": "4.0.5"
}
Solved! I had bundle.js included in my global gitinore configuration. Just had to take that out, good to go!
I'm deploying my node app to Heroku and it's trying to invoke it with nodemon rather than the node app.js I have defined. My Procfile looks like this:
web: npm start
And when I push to heroku the dyno crashes with this error:
2014-03-24T19:24:59.669412+00:00 app[web.1]: > my-app#0.0.1 start /app
2014-03-24T19:24:59.669412+00:00 app[web.1]: > nodemon app.js
2014-03-24T19:24:59.669412+00:00 app[web.1]:
2014-03-24T19:24:59.669412+00:00 app[web.1]:
2014-03-24T19:24:59.710228+00:00 app[web.1]:
2014-03-24T19:24:59.701246+00:00 app[web.1]: sh: nodemon: not found
I even tried npm installing nodemon as a package.json dependency, and checking in node_modules/nodemon but no luck. (nodemon needs to be installed with npm install nodemon -g for that to work anyway)
Any ideas?
My package.json:
{
"name": "my-app",
"version": "0.0.1",
"private": true,
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"requirejs": "~2.1.10",
"underscore": "~1.5.2",
"express": "~3.4.8",
"ejs": "~0.8.5",
"less-middleware": "~0.1.15",
"socket.io": "~0.9.16",
"tail": "~0.3.5",
"async": "~0.2.10",
"mongoose": "~3.8.5",
"mkdirp": "~0.3.5",
"ejs-locals": "~1.0.2",
"aws-sdk": "~2.0.0-rc8",
"knox": "~0.8.8",
"connect-multiparty": "~1.0.3",
"uuid": "~1.4.1",
"nodemon": "~1.0.14"
},
"devDependencies": {
"grunt": "~0.4.2",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-copy": "~0.4.1",
"grunt-contrib-requirejs": "~0.4.1",
"grunt-recess": "~0.5.0",
"grunt-contrib-cssmin": "~0.7.0",
"grunt-mocha-test": "~0.9.0",
"grunt-forever": "~0.4.1",
"matchdep": "~0.3.0",
"jshint": "~2.4.3",
"precommit-hook": "~0.3.10",
"mocha": "~1.17.1",
"supertest": "~0.9.0",
"chai": "~1.9.0",
"sinon": "~1.8.2",
"karma-sinon": "~1.0.2",
"karma-script-launcher": "~0.1.0",
"karma-chrome-launcher": "~0.1.2",
"karma-firefox-launcher": "~0.1.3",
"karma-requirejs": "~0.2.1",
"karma-html2js-preprocessor": "~0.1.0",
"karma-jasmine": "~0.1.5",
"karma-coffee-preprocessor": "~0.1.3",
"karma-phantomjs-launcher": "~0.1.2",
"karma": "~0.10.9",
"karma-mocha": "~0.1.1",
"grunt-karma": "~0.6.2",
"karma-chai": "~0.1.0"
},
"config": {
"precommit": {
"lint": true
}
},
"engines": {
"node": "0.10.x"
}
}
Update
Sorry to have left everyone hanging all this time! If I remember correctly my issue in the end was my buildpack which was overriding the web: role in my Procfile.
I've since switched to different buildpacks, namely:
ddollar/heroku-buildpack-multi
With the following .buildpacks file:
ryandotsmith/nginx-buildpack
heroku/heroku-buildpack-nodejs
And my Procfile looks like this:
web: bin/start-nginx ./node_modules/.bin/forever --minUptime 10000 --spinSleepTime 1000 app.js
Change your Procfile to this:
web: node app.js
Being app.js the entry point to your app.
This is assuming you don't really need nodemon in your app, since you have listed it at the package.json sample you provided.
Recently I'm working on deployed my node js appication in heroku by using nodemon, for it's working fine.
we have to follow few step to reslove nodemon is not found.
1)Package.json
npm start: nodemon server.js
2)We need to modified procfile like below.
web: nodemon server.js
3)Use below command line to login for heroku
$ heroku login
4)Create new application
$heroku create <appication-name>
I think most of the developer directly deployed to heroku through github Id. Locally node_modules are work fine ,after deployed your application in heroku (inside we are n't able to access the node_modules), so for that we have access the respository.
5)Clone the repository from heroku
$ heroku git:clone -a <application-name>
$ cd cv-application
Now we are able access the application.
6)Delete you node_modules and try to install package by using below command.
$ npm install.
Deploy your changes.
$ git add .
$ git commit -am "make it better"
$ git push heroku master.
npm version sholud be 6.4.1.
I know that OP got the answer but I thought I might share what worked for me, in a slightly different senario:
Procfile contains the following:
web: npm start
And for my package.json file I defined:
"scripts":{
"start": "node ./bin/www"
}
And that fixed this issue for me.
Include nodemon as dev dependencies not as dependencies.
using this command remove nodemon.
npm uninstall nodemon
now install nodemon
npm install -D nodemon
In production or in deployment you shouldn't be using nodemon.