I have a package placed in a private GitLab repository. But whenever I try to install this package, after installation, it does not include files that it contains. Only a single file index.tsx gets included.
my original package files:
And its source folder contains all the source code files
After I install the package I only get index.tsx file.
how to solve this problem
Related
Every time when I install any npm package, it creates a folder called 'tmpnodejsnpm-cache'. See the picture below.
Why does this happen?
The unwanted generated folder
I have a very simple web project and I'm using npm init to create the package.json file for the project. My project structure is below:
ProjectFolder
--app /this is the folder for js files
--css
--scss
--lib /this is for files like jQuery
--index.html
When adding a node package, it will create a node_modules folder like this:
ProjectFolder
--node_modules
--app /this is the folder for js files
--css
--scss
--lib /this is for files like jQuery
--index.html
Let's say I add jquery through npm install and make it a dependency. Is it good practice to link to the jquery file in node_modules from my index.html or move the jquery file to my lib folder?
Is there a way to move the jquery file to my lib folder when installing?
I don't want to move the node_modules folder to the server and want to know the best practice.
Your package.json is essentially your link. It contains a list of the packages you are dependent on and their versions. If you install something using npm install it has to be a published npm package on an npm repository somewhere (either public or private). It downloads a zipped version of the npm package and unzips it into node_modules. Anything in there is automatically then available to your app. Hope that helps.
I use npm in my client side development.
I use ES6 and I import modules to mapApp.js file from library that I installed in node_modules folder with help of npm tool.
Here is how I import module to mapApp.js file:
import GML from 'ol/format/GML';
Where is 'ol/format/GML' is relative path to node_modules folder.
At some point I create my own module(in config.js file) outside of node_modules folder and I need to import it to mapApp.js file.
Here is picture of project archeticture:
My question is how can I config npm to make search for imports not only in node_modules folder but,
also in specific folder outside of node_modules?
I have built a project generator for my company. It's a globally installed npm package, that when run, takes the entire contents of a /template directory inside the package and copies it to the user's chosen destination.
Inside /template I have 2 files that npm pack refuses to include in the final published module:
/template/.gitignore
/template/.npmrc
Everything else, including other hidden files, get packed as expected.
These 2 files are not in any root (or nested) .gitignore files, and I'm not manually specifying any files array in any package.json that npm might pick up on.
This is intentional behaviour https://docs.npmjs.com/misc/developers#keeping-files-out-of-your-package
The workaround was to create .gitignore.template and rename on install
Explicitly adding to files in package.json will force npm pack to include the files
"files": [
"dist",
"dist/template/.npmrc",
"dist/template/.gitignore"
]
I have been using an NPM for angular-4 which support drag and drop objects (ng2-drag-drop). I found a missing functionality and decide to add it to the package.
What I did is forking the original project and adding my changes. after commit/push to my git I then used the following command to install my NPM :
npm install https://github.com/..... --save
the NPM installed successfully however when looking in my node_modules I see that the source files are missing and I have only the root directory including the package.json and some other files . any source files are missing.
I then tried to instal the NPM directly from the author git so instead of running :
npm install ng2-drag-drop --save
I used
npm install https://github.com/ObaidUrRehman/ng2-drag-drop.git --save
and I had the same issue with my fork.
Why the installation is different between the author git and the named package ? isn't it taking the files from the same location ? if no, what should I do to make it work ?
The reason you are not able to see the src folder is
If you see the git repo you will find two files
gitignore & npmignore.
In that npm ignore file you will find the src has been ignored to be prevent it from being added to the package when running npm commands .
Keeping files out of your package
Use a .npmignore file to keep stuff out of your package. If there's no
.npmignore file, but there is a .gitignore file, then npm will ignore
the stuff matched by the .gitignore file. If you want to include
something that is excluded by your .gitignore file, you can create an
empty .npmignore file to override it. Like git, npm looks for
.npmignore and .gitignore files in all subdirectories of your package,
not only the root directory.
You need to overwrite these settings to be able to get src contents in node modules when you do npm install