npm install - how to avoid bowercopy dependency? And install dependencies using webpack - javascript

bowercopy is a deprecated tool for newer projects
Below task(from here) is the grunt task using bowercopy tool as dependency:
var JS_VENDOR_PATH = 'public/js/vendor',
CSS_VENDOR_PATH = 'public/css/vendor';
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-bowercopy');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.initConfig({
clean: {
'vendor-js': JS_VENDOR_PATH,
'vendor-css': CSS_VENDOR_PATH
},
bowercopy: {
options: {
},
js: {
options: {
destPrefix: JS_VENDOR_PATH
},
files: {
'todomvc-common.js' : 'todomvc-common/base.js',
'jquery.js' : 'jquery/jquery.js',
'underscore.js' : 'underscore/underscore.js',
'backbone.js' : 'backbone/backbone.js'
}
},
css: {
options: {
destPrefix: CSS_VENDOR_PATH
},
files: {
'todomvc-common.css':'todomvc-common/base.css'
}
}
}
});
grunt.registerTask('default', ['clean','bowercopy']);
};
We get deprecation issues, as shown below:
$ npm install
npm WARN deprecated bower#1.8.8: We don't recommend using Bower for new projects. Please consider Yarn and Webpack or Parcel. You can read how to migrate legacy project here: https://bower.io/blog/2017/how-to-migrate-away-from-bower/
npm WARN deprecated coffee-script#1.3.3: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
npm WARN deprecated minimatch#2.0.10: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch#0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated minimatch#0.3.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
npm WARN deprecated graceful-fs#1.2.3: please upgrade to graceful-fs 4 for compatibility with current and future versions of Node.js
audited 197 packages in 2.475s
found 29 vulnerabilities (6 low, 6 moderate, 17 high)
run `npm audit fix` to fix them, or `npm audit` for details
Npm version is 6.11
How to remove bower & bowercopy dependency in this grunt task? And use webpack instead of grunt...
{
"name": "xxx",
"version": "1.0.0",
"scripts": {
"prepublish": "grunt",
"build": "grunt",
"start": "open index.html || sensible-browser index.html || xdg-open index.html"
},
"repository": {
"type": "git",
"url": "https://github.com/xxxx"
},
"bugs": {
"url": "https://github.com/xxxx/issues"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-bowercopy": "^1.2.4",
"grunt-contrib-clean": "^0.6.0"
},
"dependencies": {
"express": "^4.13.3"
}
}

Related

Yarn Install - how to force the latest minor version and patch of node (10.x.x)

I have a Node app that is tested on node 10. I am using yarn as a dependency manager. As my app test is run on CI with the latest version of node 10, I want to make sure that all developers have installed the latest 10.x.x version when running any yarn command.
For example, let's say the current latest node version is 10.22.1, then I want to stop the yarn install if the developer is on 10.22.0 or 10.11.1.
Using the engine directive in package.json I tried the following syntax but no avail.
{
"engines": {
"node": "^10.x.x",
}
}
{
"engines": {
"node": "^10",
}
}
{
"engines": {
"node": ">10.0.0 <11.0.0",
}
}
{
"engines": {
"node": "10",
}
}
All of these allow any node with major version 10.
As per the yarn documentation (https://classic.yarnpkg.com/en/docs/package-json/), the preinstall is called before the package is installed.
If defined, the preinstall script is called by yarn before your package is installed.
So I would go with something like this in your package.json:
"scripts": {
....
"preinstall": "./scripts/preinstall.sh",
}
Your preinstall.sh could be:
#!/bin/bash
currentver="$(node -v)"
requiredver="v10.0.0"
if [ "$(printf '%s\n' "$requiredver" "$currentver" | sort -V | head -n1)" = "$requiredver" ]; then
echo "Version is good so let's go with install"
else
echo "Please install the node version greater than v10.0.0"
exit -1
fi
So if your developer has a version less than v10.0.0, the above script will fail and will in turn fail the yarn install command.
Note: Credit to https://unix.stackexchange.com/questions/285924/how-to-compare-a-programs-version-in-a-shell-script for shell script for version comparison.
As we have in the npm doc :
to specify acceptable version ranges up to 1.0.4, use the following syntax:
Patch releases: 1.0 or 1.0.x or ~1.0.4
Minor releases: 1 or 1.x or ^1.0.4
Major releases: * or x
So, if you want to ask for only the 10.22.1 version or newer you should use ~10.22.1 or ^10.22.1
And it's another option to pin the version (you can read more about it from this link) by using the exact version like:
{
"engines": {
"node": "10.22.1",
}
}

Cannot find modules that have been installed locally by NPM

I am working on a tool and I have installed some modules locally through NPM, and I get errors when I try to require these modules through NodeJS. I am working in Windows 10, I have already tried setting up NODE_PATH etc.
Below is the structure of my files:
->project
---->node_modules
---->src
-------->css
-------->js
----------->index.js
---->package.json
---->index.html
I populate the index.html by using index.js etc.
Below is the code of my package.json:
{
"name": "bip39",
"version": "1.0.0",
"description": "A tool for converting BIP39 mnemonic phrases to addresses and private keys.",
"directories": {
"test": "tests"
},
"dependencies": {
"bip39": "^2.6.0",
"bigi": "^1.4.2",
"create-hmac": "^1.1.7",
"nem-sdk": "^1.6.7"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/PavlosTze/bip39.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/PavlosTze/bip39/issues"
},
"homepage": "https://github.com/PavlosTze/bip39#readme"
}
Below is my require() code:
var createHmac = require("create-hmac");
var BigInteger = require("bigi");
const bip39 = require("bip39");
const nem = require("nem-sdk").default;
I have done the following steps on NPM:
1) npm init
2) npm install bip39
3) npm install nem-sdk
4) npm install bigi
5) npm install create-hmac
All these files are inside the node_modules, but still, whenever I run the code in the browser I get an 'Error: Cannot find module "bip39"', etc. for all modules.
EDIT: On another directory that I have cloned the same tool, before I merged it with another one, I get no error and everything works correctly, including the require(). etc. Do you need any of those files as well?
Can someone help me please?
try this :
rm -rf node_modules
npm install

Error: Could not locate the bindings file better-sqlite3.node

The Problem
There are some problem with maybe my installation of better-sqlite3 because when I try to execute my index.js (click to show it on pastebin) with
node index.js
there is always the same result. I tried on MacOS, it works but in my machine Linux Lite Ubuntu based distro aren't it gave me the following same error:
/home/mp8/webproject/electron-better-sqlite/node_modules/bindings/bindings.js:96
throw err
^
Error: Could not locate the bindings file. Tried:
→ /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/build/better_sqlite3.node
→ /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/build/Debug/better_sqlite3.node
→ /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/build/Release/better_sqlite3.node
→ /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/out/Debug/better_sqlite3.node
→ /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/Debug/better_sqlite3.node
→ /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/out/Release/better_sqlite3.node
→ /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/Release/better_sqlite3.node
→ /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/build/default/better_sqlite3.node
→ /home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/compiled/8.11.3/linux/x64/better_sqlite3.node
at bindings (/home/mp8/webproject/electron-better-sqlite/node_modules/bindings/bindings.js:93:9)
at Object.<anonymous> (/home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/lib/database.js:4:40)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/mp8/webproject/electron-better-sqlite/node_modules/better-sqlite3/index.js:2:18)
What is my purpose?
I want to use better-sqlie33 as my database because sqlite3 doesn't gave the node 8.x and later support.
What I tried:
This trouble shooting guide number one and two, but I still had the same error.
make init, first installed better-sqlite3 gave me the error file make/makefile not found. I got the same error when I do npm install better-sqlite3 --save
Make sure better_sqlite3.node are on my node-modules path. yeah it isn't there.
What I want?
I want to run my index.js correctly like I ran it on Mac.
Dependecies
package.json after make init, if not it just a better-sqlite3 dependencies
{
"_from": "better-sqlite3",
"_id": "better-sqlite3#4.1.4",
"_inBundle": false,
"_integrity": "sha512-Y11HN9PQ9YUeKFMrmiHyOLAKElk2ATJzBZJvuzNwTMxoS7vUEEyLnUCtcBFqViLwbomr0RQwp2MBy/ogxF50PA==",
"_location": "/better-sqlite3",
"_phantomChildren": {},
"_requested": {
"type": "tag",
"registry": true,
"raw": "better-sqlite3",
"name": "better-sqlite3",
"escapedName": "better-sqlite3",
"rawSpec": "",
"saveSpec": null,
"fetchSpec": "latest"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "https://registry.npmjs.org/better-sqlite3/-/better-sqlite3-4.1.4.tgz",
"_shasum": "9fe1dcf7b699087b98b1997cbb00261e265897e2",
"_spec": "better-sqlite3",
"_where": "/home/mp8/webproject/electron-better-sqlite",
"author": {
"name": "Joshua Wise",
"email": "joshuathomaswise#gmail.com"
},
"bugs": {
"url": "https://github.com/JoshuaWise/better-sqlite3/issues"
},
"bundleDependencies": false,
"dependencies": {
"bindings": "^1.3.0",
"integer": "^1.0.5"
},
"deprecated": false,
"description": "The fastest and simplest library for SQLite3 in Node.js.",
"devDependencies": {
"benchmark": "^2.1.4",
"chai": "^4.1.2",
"cli-color": "^1.2.0",
"fs-extra": "^5.0.0",
"mocha": "^4.1.0",
"sqlite": "^2.9.0"
},
"gypfile": true,
"homepage": "http://github.com/JoshuaWise/better-sqlite3",
"keywords": [
"sql",
"sqlite",
"sqlite3",
"custom",
"aggregate",
"database",
"transactions"
],
"license": "MIT",
"name": "better-sqlite3",
"repository": {
"type": "git",
"url": "git://github.com/JoshuaWise/better-sqlite3.git"
},
"scripts": {
"benchmark": "node benchmark",
"install": "node-gyp rebuild",
"install-debug": "node-gyp rebuild --debug",
"lzz": "lzz -hx hpp -sx cpp -k BETTER_SQLITE3 -d -hl -sl -e ./src/better_sqlite3.lzz",
"posttest": "rm -r ./temp/",
"prepublishOnly": "npm run lzz",
"pretest": "rm -r ./temp/ || true && mkdir ./temp/",
"rebuild": "npm run lzz && node-gyp rebuild",
"rebuild-debug": "npm run lzz && node-gyp rebuild --debug",
"test": "$(npm bin)/mocha --bail --timeout 5000 --slow 5000"
},
"version": "4.1.4"
}
my machine
Linux Lite 4.0, Ubuntu Based.
NVM (Node version Manager)
Node 8.11.1
NPM 5.6
I had a problem that looks like your problem
just try that:
projectToto > $ sudo rm -rf node_modules/
projectToto > $ npm install bindings
npm about binding -> https://www.npmjs.com/package/bindings
I ran into a similar situation until I realized I hadn't explicitly installed build-tools on that machine. Here's what resolved it for me (Ubuntu) when run from inside the project directory
$ rm -rf node_modules/
$ rm package-lock.json
$ npm install build-tools -g
$ npm install
For me, the problem turned out to be a circular dependency in my project (angular 10.1.1, node 12.22.6).
Figuring that out was a little tricky. The Angular compiler gave multiple "WARNING in Circular dependency detected: ..." errors, but none of them included the files where the error was actually introduced. I had to walk the project back until a commit where the problem didn't occur, then investigate what changed. That change seemed pretty innocuous - one file exported a constant that was imported by another. Changing the direction of that export solved the problem.
If nothing works....
create a new folder :
install a fresh copy with npm, which will create node_module folder with all the required files.
copy node_module folder and replace with the existing project node_module folder.
close cmd
restart server.
And it worked for me....

Travis CI NodeJs build runs locally but gets a permission denied on Travis CI

So when I run locally the mocha test inside my repo It works just fine but when I push a commit and it runs on travis CI I keep getting this error:
sh: 1: mocha: Permission denied
npm ERR! Test failed. See above for more details.
my .travis.yml
language: node_js
node_js:
- "6"
install:
-npm install
before_script: npm install -g mocha
before_script: chmod 0777 ./node_modules/.bin/mocha
package.json
{
"name": "skeletonapp",
"version": "0.0.0",
"description": "skeletonapp",
"main": "index.js",
"author": {
"name": "li"
},
"scripts": {
"test": "mocha"
},
"dependencies": {
"chai": "^3.5.0",
"mocha": "^3.1.2"
}
}
structure of files
https://travis-ci.org/LiamDotPro/Travis-CI-NodeJS-Skeleton---Mocha-Chai/builds/173340318
test.js
var assert = require('assert');
describe('Array', function () {
describe('#indexOf()', function () {
it('should return -1 when the value is not present', function () {
assert.equal(-1, [1, 2, 3].indexOf(4));
});
});
});
Turn on the execute permission on node_modules/.bin: https://github.com/travis-ci/travis-ci/issues/6828#issuecomment-258581083
Or, remove node_modules from your Git repository, and let Travis install it with npm install. (See https://docs.travis-ci.com/user/languages/javascript-with-nodejs#Travis-CI-uses-npm.)
Do not install mocha to Travis-CI manually. It's here by default.
Just remove your before_script's statements from the .travis.yml file.

Bower v1.5.2 : EINVALID errors when installing dependencies

Since updating bower to version 1.5.2, a get EINVALID error when bower is installing :
font-awesome : The "main" field cannot contain font, image, audio, or video files
select2 : The name has to end with a lower case character from a to z
bootstrap-datetimepicker : The "main" field cannot contain minified files
...
With previous version of bower (1.3.12), there was no error.
Is that possible to ignore this errors?
My bower.json file :
{
"name": "project",
"version": "1.0.0",
"dependencies": {
"jquery": "components/jquery#~2.1.1",
"js-cookie": "~2.0",
"bootswatch-scss": "~3",
"bootstrap-sass-official": "3.3.*",
"select2-bootstrap-css" : ">=1.4.6",
"tinymce": "4.2.*",
"bootstrap-table": "~1.8",
"bootstrap-datepicker": "~1.4",
"eonasdan-bootstrap-datetimepicker": "~4.15",
"moment": "~2.10",
"select2-bootstrap-theme": "0.1.0-beta.4",
"hinclude": "0.9.*"
}
}
Update
At this time, I regress to version 1.3.12
npm uninstall bower -g
npm install -g bower#1.3.12

Categories