You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add notes about `node` usage of `name` field
* Address feedback
* Use Node.js instead of "node". clarify Node does not require name.
* Added notes clarifying import behavior for a multiply installed package
* )
Copy file name to clipboardexpand all lines: research/name.md
+13
Original file line number
Diff line number
Diff line change
@@ -41,12 +41,25 @@ Analysis of the `name` property
41
41
- One scope must only ever point to one registry.
42
42
- One registry can host multiple scopes.
43
43
44
+
### Node.js
45
+
46
+
- Node.js does not require a `name` field.
47
+
- Importing a package from another package is based on the path it is installed at in `node_modules`, NOT the `name` field in `package.json`.
48
+
- If a package is named `foo` but is installed or symlinked from `node_modules/bar`, it is found as `import('bar')`
49
+
- If a package is installed under two paths (e.g. with `npm install cowsay1@npm:cowsay cowsay2@npm:cowsay`) then importing either will result in *different* module objects. If the package is instead *linked* from two paths in `node_modules` (e.g. with `pnpm install cowsay1@npm:cowsay cowsay2@npm:cowsay`), then importing either will result in the *same* module object.
50
+
- The `name` field *can* be used within a package to refer to the same package<sup>[4]</sup>. That is, if you have a `package.json` file with `"name":"foo"`, then inside that directory, `import("foo")` or `import("foo/bar")` will look at that directory before consulting `node_modules`.
51
+
- In order to enable self-imports by name, `package.json` must define an `exports` field.
52
+
- Neither a `main` field, nor a package-relative subpath will suffice instead of `exports`. Self-imports might *seem* to work if the package happens to be installed into `node_modules`.
53
+
- The scope is part of the package name for purposes of self-reference. In a package with `"name": "@scope/foo"`, you must `import('@scope/foo')`, not e.g. `import('foo')`.
0 commit comments