Node_modules and Ionic


What is the relationship between those node_modules, NodeJS, and Ionic in the context of an Ionic app?
I want to understand where each sits and why do I have a node_modules under my Ionic app folder.

CPAN was (I believe) the first distributed archive for software libraries with automated dependency management. NPM is like that, but for JavaScript stuff instead of Perl. NodeJS was developed because somebody thought it would be neat to write programs in JavaScript that didn’t run inside a browser environment. (I’m still not convinced that was a very good idea).

So npm’s registry contains both things that run hosted under a NodeJS environment, things that run in a browser, and things that can do either. Ionic uses npm for dependency management, and here’s where things get complicated, because “Ionic” isn’t a monolithic thing. The Ionic CLI is in charge of application building (most of which is now delegated to Angular’s CLI). The package.json file in your app root directory tells what dependent NPM packages your app needs, and NPM’s dependency management figures out what in turn those libraries depend on. All that stuff goes inside the node_modules directory of your app, and parts of it are incorporated into your ultimate app bundle.

The Ionic framework is itself an NPM package like any other, and the version of it used in your app also sits in node_modules. This is why the same version of the Ionic CLI can build multiple apps that use different framework versions, and the source of much confusion in the forums about what version of “Ionic” people think they are using.

Node.js itself in the context of an Ionic app is only used during the build process - this is why you see separate sets of dependencies and devDependencies in package.json. devDependencies are used during building, but not included in the app. Ordinary dependencies are bundled with the app, and - crucially - must all be things that are capable of running in a browser environment (cf your other thread about crypto).

Hope some of that was at least marginally useful.

that was incredibly useful! Thank you.

Off-topic (but I’m curious): why do think that was not a good idea?