I'm new to nodejs and npm, just a question on dependencies and devDependencies
When I create a new react or Angular project, then I added a new required package by
npm install xxx --save
so the command above add the new package entry to "dependencies" in package.json file.
then I run npm start. The project is working OK and it is using the package I just installed.
But when I run npm start, I'm still in development environment, isn't it? and if the entry is not added to devDependencies, how can the application still run in development? I'm confused
The difference between these two, is that devDependencies are modules which are only required during development, while dependencies are modules which are also required at runtime. So while development we use both of them. For more details check here.
Related
I download source code of (Nestjs)[https://github.com/nestjs/nest] framework and try to install its dependencies by running npm ci and after that lerna bootstrap. It works fine some how. But when I run tests it fails on nest-application.spec.ts file arguing it has #nestjs/microservices dependencies which is not resolved. As I see in core package node_modules folder there is only a symlink to common package. Although in core's package.json file #nestjs/microservices is marked as peer dependencies but lerna does not put it's symlink in node_modules folder. I also though that was an issue and opened a pull request https://github.com/nestjs/nest/pull/10165 which added #nestjs/microservices as devDependencies in package.json file which got rejected by kamil. If thats not a issue how can I install peer dependencies by lerna or any other method? How do themselves develop the project? Of course I can manually symlink the folder but I'm sure kamil is not doing it this way :)
Each time when I start a new project I download many dependencies and configure some settings in VS Code again and again. For example I run these commands like npm install --save-dev webpack and npm install eslint --save-dev and copy some config files like .eslintrc.
Is there any way to avoid this?
I use npm and VS code.
the possible way is to delete the new node module folder and package.json from new installed project, and copy it from the old project.
there is no legal way to perform a new project without the installation of required packages through npm.
I have just started using yarn and I can't figure out how to link a globally installed package to a project. With npm I would just run npm link <package-name> but it doesn't work with yarn.
when I run yarn link <package-name> it gives this error:
yarn link v1.22.4
error No registered package found called "express".
info Visit https://yarnpkg.com/en/docs/cli/link for documentation about this command.
The link functionality is not really meant for linking global packages to a project. It is meant to link a package that you are working on to another project that you are working on. The fact, that the npm link command can be used to link globally installed packages to the current project is just an implementation detail of npm. From the yarn docs:
For the vast majority of packages it is considered a bad practice to have global dependencies because they are implicit. It is much better to add all of your dependencies locally so that they are explicit and anyone else using your project gets the same set of dependencies.
So you should just add the dependencies via yarn add <package-name>.
I was using Node 9.3.0 and npm 5.6.0
I developed a library (let's call it Foo) which was hosted on GitHub. In its package.json, it has several devDependencies, but doesn't have any dependencies.
Then I created a new project called Bar and run npm install my-github/Foo. Instead of the single package, 140 packages were installed and all of them are Foo's devDependencies which are unnecessary for Bar.
According to several other questions, this should not happen. I tried --prod and --only=prod but did no change to the situation.
So, what is the problem?
If you have a project that depends on packageA and you yarn add packageA but packageA has a devDependency on packageB to build, shouldn't that cause packageA to not work for you? Since packageA won't be able to build unless its devDependencies are installed too?
I guess my main question is if a pacakge has a devDependency on a built tool like babel, how does it get built and work when it gets yarn added by a project? Shouldn't build tools like webpack be a normal dependency?
No, they shouldn't, because the package that is yarn added is already built in an environment where the devDependencies are available. For example, when a package needs babel or webpack to build, then during the publishing a built bundle is created in a CI/CD pipeline that is valid es5 code and that is what you pull from npm. No build required after that.
GOOD MORNING :)
If you are having dependency problems on your dependencies of package.json, it is very simple to solve =]
What happens is that the dependency modules that the modules of your project need (dependencies) must be installed in the global npm as a package node (module), that is:
npm install -g youPackageName
If you have already installed a module in other projects or in the current project and want to turn it into a global package, you can use the command:
npm link youPackageName