aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/runtime/modules.md11
-rw-r--r--packages/bun-types/tests/worker.test-d.ts4
2 files changed, 11 insertions, 4 deletions
diff --git a/docs/runtime/modules.md b/docs/runtime/modules.md
index 9b8f083d1..207315804 100644
--- a/docs/runtime/modules.md
+++ b/docs/runtime/modules.md
@@ -98,21 +98,24 @@ import { stuff } from "foo";
The full specification of this algorithm are officially documented in the [Node.js documentation](https://nodejs.org/api/modules.html); we won't rehash it here. Briefly: if you import `from "foo"`, Bun scans up the file system for a `node_modules` directory containing the package `foo`.
-Once it finds the `foo` package, Bun reads the `package.json` to determine how the package should be imported. Unless `"type": "module"` is specified, Bun assumes the package is using CommonJS and transpiles into a synchronous ES module internally. To determine the package's entrypoint, Bun first reads the `exports` field in and checks the following conditions in order:
+Once it finds the `foo` package, Bun reads the `package.json` to determine how the package should be imported. To determine the package's entrypoint, Bun first reads the `exports` field and checks for the following conditions.
```jsonc#package.json
{
"name": "foo",
"exports": {
- "bun": "./index.js", // highest priority
+ "bun": "./index.js",
"worker": "./index.js",
- "module": "./index.js",
"node": "./index.js",
- "default": "./index.js", // lowest priority
+ "require": "./index.js", # if importer is CommonJS
+ "import": "./index.mjs", # if importer is ES module
+ "default": "./index.js",
}
}
```
+Whichever one of these conditions occurs _first_ in the `package.json` is used to determine the package's entrypoint.
+
Bun respects subpath [`"exports"`](https://nodejs.org/api/packages.html#subpath-exports) and [`"imports"`](https://nodejs.org/api/packages.html#imports). Specifying any subpath in the `"exports"` map will prevent other subpaths from being importable.
```jsonc#package.json
diff --git a/packages/bun-types/tests/worker.test-d.ts b/packages/bun-types/tests/worker.test-d.ts
index 604e0a501..65cb82c5b 100644
--- a/packages/bun-types/tests/worker.test-d.ts
+++ b/packages/bun-types/tests/worker.test-d.ts
@@ -1,3 +1,7 @@
+import { Worker } from "node:worker_threads";
+
+const workerthread = new Worker("./worker.js");
+
const worker = new Worker("./worker.ts");
worker.addEventListener("message", (event: MessageEvent) => {
console.log("Message from worker:", event.data);