Modules
in node_modules
, we have a folder .bin/
. This is whe
- normally these binaries are symlinks to the binaries that are stored within each package's directory in
node_modules
- when are within a project and run a command that is not globally installed, it looks in the
.bin/
directory for that executable- ex. running
jest test
in the project will look for an executable calledjest
withinnode_modules/.bin
and execute it.
- ex. running
How Node resolves modules
When we import myFunction from 'moduleB'
, the moduleB
module will be searched for in a node_modules
directory at the current level. It will search:
./node_modules/moduleB.js
./node_modules/moduleB/package.json
(if it specifies a "main" property)./node_modules/moduleB/index.js
if it doesn't find the module here, it will go up one level and continue the search in the same pattern
../node_modules/moduleB.js
../node_modules/moduleB/package.json
(if it specifies a "main" property)../node_modules/moduleB/index.js
And so on, until the module is either found or there are no more levels to search.
the node module resolution algorithm is recursive, meaning when looking for package A, it looks in local node_modules/A
, then ../node_modules/A
, then ../../node_modules/A
, and so on.
- unless we use strict versioning (ie. omitting
^
in package.json.dependencies) the version listed in package.json is not the version our package uses. Rather, it defines a range that is allowed to be installed. To see the actual version, check yarn.lock
Package.json
UE Resources
Children
Backlinks