3 ms·
What magic is there for finding node_modules? It's in the same directory as package.json. Very similar (though simpler) to how Python modules work. There's als
by jampekka 2y ago
What magic is there for finding node_modules? It's in the same directory as package.json. Very similar (though simpler) to how Python modules work.
There's also usually one global package dir, but that's almost exclusively used for runnable binaries, and not even really needed when there's npx.
If you think Python packaging has less magic, you probably don't know it very deeply.
I lost all hope for Python package management to ever get better when PEP 582 got rejected for some stupid tribal reasons.
https://peps.python.org/pep-0582/ https://peps.python.org/pep-0582/
- dvdkon 2y agoI was talking more about the package lookup when running code, via e.g. `node script.js`. I think it looks in all parent directories of the CWD, or maybe of the script? It's not too complicated, but it is "more magic" IMO. Actually building Python packages is pretty complex, but that's the case for JS too. Java avoids this by distributing compiled libraries.
- jampekka 2y agoIt looks up from script.js'd directory or the earliest parent with node_modules. Not CWD. A lot like "import somemodule" in script.py tries to import somemodule.py file from the directory script.py is in. Traversing to the parent is especially nice for scripts. In python having scripts outside the module directory is quite painful. Gyp is a lot easier than Python setup.py. The "easy" Java packages are comparable to pure Python/pure JS packages. With e.g. C bindings JNI/Java packaging is a horrid pain.