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

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.

Related

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.

custom npm package not found in my service

There is a similar post here:
My custom NPM Package is not found,
but that did not resolve my issue.
Could not find a declaration file for module '#dc_microurb/common'.
'/Users//Projects/ticketing/auth/node_modules/#dc_microurb/common/build/index.js'
implicitly has an 'any' type. Try npm install #types/dc_microurb__common if it exists or add a new declaration
(.d.ts) file containing `declare module '#dc_microurb/common';
There is no #types/dc_microurb__common and I am unclear as to why it is suggesting to create a new .d.ts file, when that happens automatically during the build process.
This is the package.json file inside my published package:
{
"name": "#dc_microurb/common",
"version": "1.0.5",
"description": "",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"files": [
"./build/**/*"
],
"scripts": {
"clean": "del ./build",
"build": "npm run clean && tsc",
"pub": "git add . && git commit -m \"Updates\" && npm version patch && npm run build && npm publish"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"del-cli": "^3.0.1",
"typescript": "^4.0.5"
},
"dependencies": {
"#types/cookie-session": "^2.0.41",
"#types/express": "^4.17.9",
"#types/jsonwebtoken": "^8.5.0",
"cookie-session": "^1.4.0",
"express": "^4.17.1",
"express-validator": "^6.6.1",
"jsonwebtoken": "^8.5.1"
}
}
Anybody with experience in publishing packages on npm where TypeScript is involved? I am unclear as to why this package is not being found by my auth service when it is successfully installed inside that service.
Did I mess up in the way I am exporting inside my common/src/index.ts file?
export * from './errors/bad-request-error';
export * from './errors/custom-errors';
export * from './errors/database-connection-error';
export * from './errors/not-authorized-error';
export * from './errors/not-found-error';
export * from './errors/request-validation-error';
export * from './middlewares/current-user';
export * from './middlewares/error-handler';
export * from './middlewares/require-auth';
export * from './middlewares/validate-request';
Does it all have to be inside a module.exports instead?
So after reviewing a few blogs on Medium on how this is done, I noticed a couple of things.
Inside my tsconfig.js, this was missing:
/* Advanced Options /
"forceConsistentCasingInFileNames": true / Disallow inconsistencies */
So I manually added it in, secondly, I noticed something I meant to remove earlier but forgot. So instead of this:
{
"name": "#dc_microurb/common",
"version": "1.0.5",
"description": "",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"files": [
"./build/**/*"
],
I needed to have it like this:
{
"name": "#dc_microurb/common",
"version": "1.0.6",
"description": "",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"files": [
"build/**/*"
],
After making those couple of corrections, now my package is available to my auth service.

NPM Excluding files automatically >

I am trying to publish a package on npm. It's poppler's pdftotext portable.
The lib folder structure is like this:
"lib/libjpeg.so.9",
"lib/libjpeg.so.9.2.0",
"lib/libjpeg.so.9.2.0",
"lib/libpoppler.so",
"lib/libpoppler.so.98",
"lib/libpoppler.so.98.0.0"
but when I pack it, npm automatically removed other files and only keeps libjpeg 9.2.0 and libpoppler.so.98.0.0
Why are other files removed? There is no ignore file; no npmignore nor gigignore.
The type of removed file is Link to shared library (application/x-sharedlib) How can I include them as well ?
This is complete package.json
{
"name": "packname",
"version": "0.0.2",
"description": "dis",
"main": "index.js",
"directories": {
"lib": "lib"
},
"files": [
"bin",
"lib"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": ""
}

Private github repo as dependency is extraneous on npm install

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.

npm link not working on windows?

I'm using node v0.10.32. Windows 8.1.
My objective is to link a node application as a node_module in another main app.
I go to my-module folder and do
npm link
Then, I go to the main-app folder and do
npm link my-module
This is the result
c:\dev\main-app>npm link my-module
unbuild my-module#0.0.2
c:\dev\main-app\node_modules\my-module -> C:\Users\Nizar\AppData\Roaming\npm\node_modules\my-module -> C:\dev\my-module
But, the linkage does NOT seem to work, require('my-module') throws the following error
c:\dev\main-app>node app.js
module.js:340
throw err;
^
Error: Cannot find module 'my-module'
at Function.Module._resolveFilename (module.js:338:15)
my-module is indeed v0.0.2.
I can access it from main-app/node_module/my-module
This folder exists C:\Users\Nizar\AppData\Roaming\npm\node_modules\my-module
my-module package.json has "name": "my-module"
Moreover, %NODE_PATH% is correctly set:
c:\dev\main-app>echo %NODE_PATH%
C:\Users\Nizar\AppData\Roaming\npm\node_modules
Ideas?
There are a few things to try. On Windows, npm link is handled by creating junction points. Issuing a dir node_modules command should result in a line like:
01/15/2016 11:02 AM <JUNCTION> my-module [C:\Users\Nizar\AppData\Roaming\npm\node_modules\my-module]
Assuming that's there, then the problem is more than likely:
A lack of an index.js file (which is the default filename node uses to resolve modules)
You're using a different file than index.js as the main file of your module, in which case you need to tell node what that file is, by using the main key in your package.json file.
For example (taken from here):
{
"name": "node-js-sample",
"version": "0.2.0",
"description": "A sample Node.js app using Express 4",
"main": "index.js", // <-- LIKE THIS
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.13.3"
},
"engines": {
"node": "4.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/heroku/node-js-sample"
},
"keywords": [
"node",
"heroku",
"express"
],
"author": "Mark Pundsack",
"contributors": [
"Zeke Sikelianos <zeke#sikelianos.com> (http://zeke.sikelianos.com)"
],
"license": "MIT"
}

Resources