Looked to numerous SO questions and answers, however have not found the answer to fix the following issue.
On my local machine I run npm from the folder node_modules. This folder contains several packages from GIT-sources, however there are two folders containing custom made scripts. Each time I update package with npm install my two custom folders are gone. Luckily I made a backup and was able to restore these two. But it's also annoying, because what else is removed that I don't see??
I'm on npm version 6.13.2
Any help is of course highly appreciated.
There is no way you can prevent npm from removing those folders because they are not in your package.json.
Although there are two things that you can do which are as follows,
Create npm modules for those 2 scripts and update their entries in your package.json. Here is a link for 'how to create and publish node module'.
https://www.guru99.com/node-js-modules-create-publish.html
Create a repo for those 2 scripts and update their git paths in your package.json.
Related
I have some local modules which are inhouse developed and I copy to my node_modules folder manually.
When I do this they work fine but after I install some other stuff via ng add or npm install the folder is removed. My question is how can I prevent this from happening so I don't have to copy the files again ?
You need to specify your dependencies in package.json or else you cannot rely on them being in node_modules. Various npm commands might remove it, notably npm ci but also others.
If your package is not publicly published, some options are:
Use a non-public registry and publish it there.
Publish it as a scoped package with limited visibility. You will need a paid or organization account on npm for this. Individual accounts are US$7 a month.
Use npm link to "install" it from your local file system.
Use a postinstall or other life cycle script to have npm copy in your packages for you each time after npm ci or npm install is run.
There are likely other options, but those are the ones that come to mind immediately.
Simple question : Is it possible, in a package.json, to reference another package.json, and install its dependencies ?
Thank you.
Yes, this is possible, and this is automatically done by npm install.
If you have pkg-a that depends on pkg-b, including pkg-a in your dependencies will install both pkg-a and pkg-b when running npm install. That is because dependencies are actually references to the package.json of other packages. NPM, upon running install, builds a dependency tree of all the packages that are indirectly required by your current project, and installs all of them in the node_modules directory, and keeps track of them all in package-lock.json.
Good question! but this is not possible as you cannot internally reference one json document from another (json is just a document format, it lacks any ability to process logic, import files etc), npm is configured to run using a single package.json file so your best best would be to put all your dependencies in a single package.json file or split your project into two directories with two separate package.json files, two npm installs etc, if for some reason you require your dependencies to be separate. You could then run your two node projects separately and connect via http if you wish.
The only way that you could come close to doing this would be to write an npm start script in the package.json that cds to another directory with a package.json and runs npm install, this would however only install the dependencies in the second directory node-modules/ folder
I deleted some module folders that I had previously npm installed into a module. I also manually removed their entries in my module's package.json. Then, npm would still look for those deleted folders so I re-created the folders and npm uninstalled them, which succeeded. Is there another way to "clear" npm's graph?
Try running npm cache clean --force and then see if the problem still persists. S If would help if you posted your package.json file so that we could see if any problems exist.
The docs explain how to control which files are not sent to the npm registry when you run npm publish.
If you use .npmignore, or you're not using git that set of files differs from the set that are pushed to your source repo.
Is there a way to list the files that npm publish will send?
I know that npm pack will create a tarball that contains those files, but creating a tarball and then listing its contents seems a little clunky.
Currently, there's no such thing in npm (see this issue).
At the moment you can use some external tools that implement the functionality you're asking for, e.g. pkgfiles or irish-pub.
As of at least npm#6, you can run npm publish --dry-run to see what files are included in your package.
https://docs.npmjs.com/cli/v6/commands/npm-publish
Let's say i want to delete project folders with a bunch of localy installed npm packages such as gulp, gulp-sass or/and other package managers maybe bower with it's own packages.
Is it an easier way to just manualy shift+del whole folder and, well, I don't know, don't leave behind some conflicts or something?
Or maybe npm has a command to proper uninstall all packages, "uninit" folder, etc?
I got this problem.
At first, I copied all of packages from packages.json and run command like:
npm uninstall #typescript-eslint/eslint-plugin #typescript-eslint/parser #vue/cli-plugin-babel #vue/cli-plugin-eslint (... etc.) --save
Then, I tried to delete folder by hands, but it is deny permitions.
I open my project from VSCode and delete node_modules from tree by hands:
Delete node_modules from tree by hands from VSCode
It was delete successfully!
p.s.: The remaining files are deleted without problems manually...