Install custom npm package in another custom npm package - node.js

I have create a npm package to install "gulp" & "nunjucks" and some other features of gulp. and published it in NPM repository named (package name: xdnunjucks-test).
Now I have created new project and trying to install "xdnunjucks-test" then it is added to my new project but all the dependencies in xdnunjucks-test are not added to new project.
command: npm install xdnunjucks-test
-- I should create a custom NPM package to install all dependencies in my new projects. This will helps me to avoid run all the commands in xdnunjucks-test everytime.
single command to run multiple commands.
here are my package.json file content.
Published Custom NPM command - package.json:
{
"name": "xdnunjucks-test",
"version": "1.0.5",
"description": "Custom npm command creation",
"main": "index.js",
"scripts": {
"test": "XDNunjucks",
"start": "npm install gulp",
"bootstrap-gulp": "npm i bootstrap-gulp",
"gulp-uglify": "npm install gulp-uglify",
"gulp-sass": "npm install node-sass gulp-sass",
"gulp-imagemin": "npm install gulp-imagemin",
"gulp-minify": "npm install gulp-minify",
"gulp-livereload": "npm install gulp-livereload",
"gulp-data": "npm install gulp-data",
"browser-sync": "npm install browser-sync"
},
"keywords": [
"npm",
"test"
],
"author": "Anil",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.26.7",
"gulp": "^4.0.2",
"gulp-data": "^1.3.1",
"gulp-imagemin": "^7.1.0",
"gulp-livereload": "^4.0.2",
"gulp-minify": "^3.1.0",
"gulp-nunjucks-render": "^2.2.3",
"gulp-sass": "^4.0.2",
"gulp-uglify": "^3.0.2",
"node-sass": "^4.13.1"
},
"dependencies": {
"bootstrap-gulp": "^2.2.5"
}
}
new project package.json:
{
"name": "n-test-2",
"version": "1.0.0",
"description": "",
"main": "gulpfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"xdnunjucks-test": "^1.0.5"
}
}
After installing the "xdnunjucks-test" command. I didn't get the features of "xdnunjucks-test" in new project.
Please help in in this.
Thank you.

All the dependencies in you package xdnunjucks-test is only "bootstrap-gulp" "^2.2.5"
all other dependency from devDependency will not be installer in package.
For example if you need to use gulp-uglify in installed package xdnunjucks-test - you should move it to dependency
devDependencies are:
installed on npm install on a directory that contains package.json, unless you pass the --production flag (go upvote Gayan Charith's answer).
not installed on npm install "$package" on any other directory, unless you give it the --dev option.
are not installed transitively.
You can find more about npm dependency on stackoverflow and npm documentation

Related

Error around package files for Node.js Discord bot

I have a basic Discord bot I am trying to publish through Heroku because I can't host it locally anymore.
Should mention that it runs perfectly fine when hosted locally on my VM.
When trying to push to Heroku through cli or git I am getting an error which says:
npm ERR! cipm can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with npm install before continuing.
remote: npm ERR!
remote: npm ERR!
remote: npm ERR! Missing: enmap#^5.2.4
remote: npm ERR! Missing: eslint#^7.2.0
Tried googling and and still have no idea how these package files work, so would be grateful if someone could tell me what to change.
package.json
{
"name": "sidbot2",
"version": "2.3.2",
"description": "",
"main": "sidbot.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "sidilleth",
"license": "ISC",
"dependencies": {
"discord.js": "^12.2.0",
"enmap": "^5.2.4"
"eslint": "^7.2.0"
},
"devDependencies": {
"eslint": "^7.2.0"
}
}
Remove the eslint from dependencies as it is already present in the dev dependencies. It should look similar to this:
{
"name": "sidbot2",
"version": "2.3.2",
"description": "",
"main": "sidbot.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "sidilleth",
"license": "ISC",
"dependencies": {
"discord.js": "^12.2.0",
"enmap": "^5.2.4"
},
"devDependencies": {
"eslint": "^7.2.0"
}
}
Delete node_modules folder and execute npm install.
Also make sure that the all the changes made in package.json and package-lock.json has been committed to git.

npm ERR! while installing next.js

I have a problem like while I am trying to install next.js using npm install --save next then showing below error like
npm ERR! Unexpected end of JSON input while parsing near '...:{"eslint":"3.19.0","'
I just stack into that for past several hours.
How can I resolve that?
package.json
{
"name": "a-client-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "node server.js -p $PORT",
"build": "next build",
"start": "NODE_ENV=production node server.js -p $PORT"
},
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"react": "^16.9.0",
"react-dom": "^16.9.0"
}
}
Info:
OS: Windows 10
NodeJS: 10.16.3
NPM: 6.11.3
Thanks
The issue was due to the node cache.
npm cache clean --force
fixed the issue.
Writing answer here in case anyone else runs across this. :)

Hi. I am new to react and have a query re optimum setup procedures

The following package.json contains a lot of dependencies and a few devDependencies stuff but barring a few files it seems to have all I need excepting a few npm install commands for reactstrap, bootstrap, react-bootstrap
{
"name": "react-tutorials",
"version": "0.0.0",
"description": "",
"main": "webpack.config.js",
"dependencies": {
"babel-core": "^6.18.2",
"babel-loader": "^6.2.0",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-plugin-react-html-attrs": "^2.0.0",
"babel-plugin-transform-class-properties": "^6.3.13",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"flux": "^2.1.1",
"history": "^1.17.0",
"react": "^0.14.6",
"react-dom": "^0.14.6",
"react-router": "^1.0.3",
"webpack": "^1.12.9",
"webpack-dev-server": "^1.14.1"
},
"devDependencies": {},
"scripts": {
"dev": "webpack-dev-server --content-base src --inline --hot"
},
"author": "",
"license": "ISC"
}
// Additional dependencies and devDependencies
npm install --save reactstrap react-addons-transition-group react-addons-css-transition-group react react-dom
npm install react react-dom bootstrap react-bootstrap babel-preset-react webpack webpack-dev-server --save
npm install webpack css-loader style-loader file-loader url-loader babel-core
What is the optimal way to create a file tree for your react project via npm and what react-*** setup packages are not too difficult for a novice such as myself? Please don't suggest create-react-app - I love it but its limited. Also, can all dependencies and devDependencies be installed via npm all at once or with some files interfere with others which I've noticed before I think.
When you run each of the commands npm install --save package-here it will add that package to your package.json automatically. When you're ready to install your project from the root directory you run npm install only and it will install everything in your package.json into a node_modules folder. Other than that you should not have to change anything with your packages as far as file structure.
In addition, when you want to add a package to your dev-devependencies run npm install --save-dev or just dependencies npm install --save.

npm start showing weird error 1

I am new to react js and I have installed the dependencies for the application. Below is my package file:
package.json
{
"name": "reactapp",
"version": "0.0.0",
"description": "learn and test",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --hot"
},
"author": "john doe",
"license": "BSD-2-Clause",
"dependencies": {
"webpack": "~1.13.3",
"webpack-dev-server": "~1.16.2",
"react": "~15.3.2",
"react-dom": "~15.3.2"
},
"devDependencies": {}
}
It throws the error:
npm ERR! weird error 1
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian
npm ERR! not ok code 0
But, in the terminal while it doesn't show up anything when in scripts it is
"test": "echo \"Error: no test specified\" && exit 1"
You need to use the sudo command while installing nodejs-legacy.
Executing sudo apt-get install nodejs-legacy from your command line/shell will resolve the issue.

Azure "Web apps" service: auto-install npm modules from package.json

I deployed a node.js app in an azure "web apps" container. I added the "node_modules" folder to .gitignore and let azure install modules from package.json.
However, most modules do not get automatically installed and i have to open the instance's command line and install them manually using "npm install".
I am using node v0.12.0 and here is my package.json:
{
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"devDependencies": {
"body-parser": "^1.12.4",
"cors": "^2.6.1",
"express": "*",
"gulp": "^3.8.11",
"gulp-jshint": "^1.11.0",
"gulp-nodemon": "^2.0.3",
"moment": "^2.10.3",
"mongoose": "^4.0.3"
},
"engines": {
"node": "0.12.0"
}
}
How can I enable automatic installation of modules through azure web apps and not be obliged to push the "node_modules" folder with each commit?
Azure does not install the devDependencies.
If you need them on production, it is not devDependencies but dependencies
In your package.json, devDependencies should be renamed to dependencies
This kind of thing appens when you npm install --save-dev.
Production dependency (needed to run): npm install --save
Otherwise (build tools, jshint, etc.): npm install --save-dev

Resources