Private github repo as dependency is extraneous on npm install - node.js

This is my first time using a private repo as a dependency in another project. I think I am doing it right, but the dependency is not available in the new project after install and is not in node_modules.
Following this post I can see that I am including it in the package.json correctly like:
"myPackage": "git+https://github.com/myusername/mygitrepository.git"
When I run npm install on this package, I see this that it does not have an error, but after this dependency in the list, it is shown with extraneous(git+https://github.com/myusername/mygitrepository.git).
Even though there is the extraneous issue, there is no error, and the dependency is not available or listed in node_modules.
Update: repo_A package.json
{
"name": "project-name",
"version": "1.0.0",
"description": "Backend utility functions",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/user/repo.git"
},
"author": "me",
"license": "ISC",
"bugs": {
"url": "https://github.com/user/repo/issues"
},
"homepage": "https://github.com/user/repo#readme",
"dependencies": {
"lodash": "^4.17.4",
"mongodb": "^2.2.25",
"redis": "^2.7.1",
"winston": "^2.3.1"
}
}
Update: repo_B package.json
{
"name": "main-project-name",
"version": "1.0.0",
"description": "",
"repository": {
"type": "git",
"url": "git+https://github.com/user/repo.git"
},
"author": "someone else",
"homepage": "https://github.com/user/repo.git",
"dependencies": {
"async": "2.1.4",
"chai": "^3.5.0",
"langs": "1.1.0",
"lodash": "4.13.1",
"node-stopwatch": "0.0.1",
"request": "2.74.0",
"winston-loggly": "^1.3.1",
"utils": "user/repo_A.git#master"
},
"scripts": {
"test": "mocha"
}
}
Update for latest steps
Here are the steps I am following now to test each possible solution, followed by the output:
rm -rf node_modules
npm cache clean
npm install
Output
├─┬ async#2.1.4
│ └── lodash#4.17.4
├─┬ chai#3.5.0
│ ├── assertion-error#1.0.2
│ ├─┬ deep-eql#0.1.3
│ │ └── type-detect#0.1.1
│ └── type-detect#1.0.0
├── util#1.0.0 extraneous (git+ssh://git#github.com/user/repo_A.git#commit-ish)
.......

If you specify https then that will be looking for a login user and password I believe, which I don't think it can load automatically. I would list it simply as "user/repo" and make sure that machine has an ssh key on it that is in github like the setup described in help such as https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#platform-linux and that things are setup so that pulling down that repo does not require user interaction.
EDIT: After testing, I think the issue is that your name in the package.json does not match how you have listed it in your main project's dependencies. In my test, this resulted in the modules being installed but I got the extraneous message.

Related

npm peer dependencies not being enforced

I am trying to understand peer dependencies in npm, and could not understand the behavior below.
I have the following versions of node and npm :
$ npm -v
8.15.0
$ node -v
v16.17.0
The following directory structure:
peer-dep-test$ tree -I "node_modules"
.
├── library
│ ├── package-lock.json
│ └── package.json
└── project
├── package-lock.json
└── package.json
Library contains the following imports (#altostra/type-validations is used as an example small package here):
{
"name": "library",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"peerDependencies": {
"#altostra/type-validations": "2.6.5"
}
}
and project contains the following:
{
"name": "project",
"version": "1.0.0",
"main": "index.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"#altostra/type-validations": "1.0.2",
"library": "file:../library"
}
}
The project project has a version of #altostra/type-validations which should be incompatible with library - but I get no error on doing npm install. npm list gives the following output:
peer-dep-test/project$ npm list --all
project#1.0.0 peer-dep-test/project
├─┬ #altostra/type-validations#1.0.2
│ └─┬ #reactivex/ix-es2015-cjs#3.0.2
│ ├── #types/node#13.13.52
│ └── tslib#1.14.1
└─┬ library#1.0.0 -> ./../library
└─┬ #altostra/type-validations#2.6.5
└─┬ #reactivex/ix-es2015-cjs#3.0.2
├── #types/node#13.13.52
└── tslib#1.14.1
As per my understanding of peer dependencies,
library should expect #altostra/type-validations#2.6.5 to be installed directly in project
#altostra/type-validations#1.0.2 should conflict with the peerDependency of library, and either warn or error.
Am I missing something here?

Vue.js - ERROR in Conflict: Multiple assets emit different content to the same filename index.html

if I create a new vue.js project on my macbook and compile it with "npm run serve", I get the following error. I haven't changed any file since creating it.
markus#Markuss-MBP meinerstesprojekt % npm run serve
> meinerstesprojekt#0.1.0 serve
> vue-cli-service serve
INFO Starting development server...
ERROR Failed to compile with 1 error 6:12:51 PM
error
Conflict: Multiple assets emit different content to the same filename index.html
ERROR in Conflict: Multiple assets emit different content to the same filename index.html
webpack compiled with 1 error
vue.config.js
const { defineConfig } = require('#vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true
})
module.exports = {
chainWebpack: (config) => {
config.resolve.symlinks(true)
}
}
package.json
{
"name": "meinerstesprojekt",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.8.3",
"vue": "^2.6.14"
},
"devDependencies": {
"#babel/core": "^7.12.16",
"#babel/eslint-parser": "^7.12.16",
"#vue/cli-plugin-babel": "~5.0.0",
"#vue/cli-plugin-eslint": "~5.0.0",
"#vue/cli-service": "^5.0.1",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3",
"vue-template-compiler": "^2.6.14"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"parserOptions": {
"parser": "#babel/eslint-parser"
},
"rules": {}
},
"browserslist": [
"> 1%",
"last 2 versions",
"not dead"
]
}
npm version: 8.5.3
Node-Version: v16.14.0
Vue-Version: #vue/cli 5.0.1
The following folders are in the path:
├── README.md
├── babel.config.js
├── dist
├── jsconfig.json
├── node_modules
├── package-lock.json
├── package.json
├── public
├── src
└── vue.config.js
Do you know why this doesn't work? Unfortunately, I couldn't find the solution by searching the web
i was having this issue because of the path to the project was having spaces in the folders name
so i renamed the paths to the project and it works
Example
from user/some path here/your-project-name
to user/somePathHere/your-project-name
and everything starts to work.
Solution:
Step 1: Rename index.html to index.ejs;
Step 2: Add html: { template: './src/index.ejs' } to node_nodules/webpack/bin/webpack.js
The reason for the error may be: When the scaffolding was used to create a project, the names of multiple files were duplicated.
When you hit vue create your-project-name Select ([Vue 3] babel,eslint)
and try to npm run serve.
And also you can use vue ui to start a new project or import old one, and see everything about your project run in a GUI in your browser so you can figure out any problem.

Publishing images to be included in README.md on NPM

In this project the README.md displays the logo/pnglogo.png logo at the top of the README.md file.
We'd like the same logo to display on NPM. So we copy it into the dist/fs-validator directory where the publish files are located. This is the npm script (From package.json):
"p": "cp README.md ./projects/fs-validator/ && npm run bp && npm run b && cp -r logo ./dist/fs-validator/ && cd dist/fs-validator/ && npm publish",
If I understand correctly, this should publish the logo directory along with the other files. However the logo is not showing up at the top of the README.md within NPM. How can I fix that?
I moved the logo to the root of the repository and changed the README.md to include it like this:
![Validator](pnglogo.png)
As that works for publishing with this repository:
https://github.com/fireflysemantics/slice
However I'm still not getting any success.
Figured it out. The package.json that I was publishing did not have the Github repository fields included.
{
"name": "#fireflysemantics/validator",
"version": "0.0.9",
"peerDependencies": {
"#fireflysemantics/is": "*",
"#fireflysemantics/validatorts": "*"
},
"dependencies": {
"tslib": "^2.2.0"
}
}
Apparently these are needed in order for NPM to know where the image is located.
I changed package.json to incoulde the repository data so that it now looks like this:
{
"name": "#fireflysemantics/validator",
"version": "0.0.11",
"license": "MIT",
"bugs": {
"url": "https://github.com/fireflysemantics/validator/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/fireflysemantics/validator.git"
},
"keywords": [
"Validation",
"Javascript",
"Typescript",
"Angular Package Format"
],
"peerDependencies": {
"#fireflysemantics/is": "*",
"#fireflysemantics/validatorts": "*"
},
"dependencies": {
"tslib": "^2.2.0"
}
}
And now the logo shows up.

Private repo dependency installs but "Cannot Find Module"

I have a project that requires a private repo as a dependency. So, projectA has this included in the package.json as "projectB": "user/repo". This installs just fine, and is listed in projectA node_modules. The problem is, that node throws and error where I require the functions of the dependency. The error being that "Cannot find module projectB". As mentioned, projectB is listed in node_modules. Here is the structure of projectB:
.
├── README.md
├── file1.js
├── file2.js
├── file3.js
├── file4.js
└── package.json
It also has its own node_modules, but I've left that out. Now, here is what file1.js might look like:
function getResult (a, b) {
return a + b;
}
module.exports = { getResult }
And here is what projectA looks like:
var calculate = require('projectB').file1.getResult; // I've tried this in several other ways too
Calling calculate results in the "Cannot find module error". Have I done something fundamentally wrong in setting up for using a private repo as dependency and/or requiring it wrong?
Update projectB package.json
{
"name": "projectB",
"version": "1.0.0",
"description": "Backend utility functions",
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/user/repo.git"
},
"author": "Me",
"license": "ISC",
"bugs": {
"url": "https://github.com//user/repo/issues"
},
"homepage": "https://github.com//user/repo#readme",
"dependencies": {
"lodash": "^4.17.4",
"mongodb": "^2.2.25",
"redis": "^2.7.1",
"winston": "^2.3.1"
}
}
projectB needs to be updated to set an appropriate main, but by default this will be index.js. You could do something like the following:
// projectB/index.js
exports.file1 = require("./file1");
exports.file2 = require("./file2");
exports.file3 = require("./file3");
exports.file4 = require("./file4");
It's actually a pretty common pattern to have an index.js that does nothing but export from library files.

Install node_module from npm but it doesn't install its own node_modules - package.json

I just created a node_module with a dependency with 'validator'.
But when I install it from npm, it doesn't install the 'validator' module in its own node_module directory. I don't understand why, but it's the first time I create my own node module.
package.json:
{
"name": "validator-extended",
"description": "String validation and sanitization based on validator.js",
"version": "1.1.0",
"homepage": "https://github.com/Ayolan/validator-extended",
"keywords": [
"validator",
"validation",
"validate",
"sanitization",
"sanitize",
"sanitisation",
"sanitise",
"assert",
"extend",
"extended"
],
"author": "Vadorequest <https://github.com/Vadorequest>",
"main": "app.js",
"bugs": {
"url": "https://github.com/Ayolan/validator-extended/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/Ayolan/validator-extended.git"
},
"engines": {
"node": ">= 0.8"
},
"licenses": [
{
"type": "MIT",
"url": "https://github.com/Ayolan/validator-extended/raw/master/LICENSE"
}
],
"dependencies": {
"validator": "~3.1"
}
}
I also have a .npmignore file with this:
########################
# node.js / npm
########################
lib-cov
*.seed
*.log
*.csv
*.dat
*.out
*.pid
*.gz
pids
logs
results
node_modules
npm-debug.log
########################
# misc / editors
########################
*~
*#
.DS_STORE
.netbeans
nbproject
.idea
Should I push the node_modules/ directory into my git repository?
You should remove your existing package.json and run
npm init
to properly initialise your project. Once that's done, add validator to the dependencies. This should allow npm install to work properly and install your dependencies. Don't commit your node_modules folder.

Resources