Deno bundle is not including all re-exported types to the bundle file. The funny thing is that some symbols are but others are silently discarded. The example below is a bit complex, so please bear with me:
My library nats.ws depends on another library nats.deno.
The nats.ws library, imports dependencies for the common code in nats.deno by adding a single (nats-base-client.ts) file that does a re-export:
export * from "https://raw.githubusercontent.com/nats-io/nats.deno/v1.0.0-11/nats-base-client/internal_mod.ts";
It then specifies a mod.ts file that re-exports everything:
export * from "./nats-base-client.ts";
export { connect } from "./connect.ts";
When this is bundled by the bundler, some types such as Bench are not included in the bundled file, while others like Metric are. - The interesting part both of these classes are exported from the same file in the source and both have the same scope. Meaning they are not used outside of benching information so none of the code is referenced directly (client code will).
With 1.4.6 this worked correctly, but 1.5.0 had different issues where some of the types were bundled twice. It looks like 1.5.1 is doing some sort of filtering and deciding to drop some symbols when it shouldn't.
❯ deno bundle https://raw.githubusercontent.com/nats-io/nats.ws/master/src/mod.ts | grep Bench
Bundle https://raw.githubusercontent.com/nats-io/nats.ws/master/src/mod.ts
Check https://raw.githubusercontent.com/nats-io/nats.ws/master/src/mod.ts
❯ deno bundle https://raw.githubusercontent.com/nats-io/nats.ws/master/src/mod.ts | grep Bench
❯ deno upgrade --version 1.4.6
downloading https://github.com/denoland/deno/releases/download/v1.4.6/deno-x86_64-apple-darwin.zip
Version has been found
Deno is upgrading to version 1.4.6
downloading https://github-production-release-asset-2e65be.s3.amazonaws.com/133442384/503f1780-0ae6-11eb-9437-684aaec8a713?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20201104%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20201104T214132Z&X-Amz-Expires=300&X-Amz-Signature=c4db6b05a1b877c802742e4eac8bca60273f39d04a9127ff52d47d0ad6889b22&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=133442384&response-content-disposition=attachment%3B%20filename%3Ddeno-x86_64-apple-darwin.zip&response-content-type=application%2Foctet-stream
Version has been found
Deno is upgrading to version 1.4.6
Archive: /var/folders/1y/_rk6yz81341g5q8k1vr5nqmw0000gq/T/.tmpcjenvn/deno.zip
inflating: deno
Upgrade done successfully
❯ deno bundle https://raw.githubusercontent.com/nats-io/nats.ws/master/src/mod.ts | grep Bench
Bundle https://raw.githubusercontent.com/nats-io/nats.ws/master/src/mod.ts
"Bench": internal_mod_ts_1_1["Bench"],
var types_ts_8, nuid_ts_3, util_ts_10, error_ts_11, Metric, Bench;
Bench = class Bench {
exports_62("Bench", Bench);
"Bench": true,
"Bench": bench_ts_1_1["Bench"],
export const Bench = __exp["Bench"];
export const BenchOpts = __exp["BenchOpts"];
It looks like 1.5.1 is doing some sort of filtering and deciding to drop some symbols when it shouldn't.
1.5.1 does tree shaking, prior to 1.5 it didn't. If it is doing it inappropriately it is a bug, but it needs further investigation to determine exactly what the correct behaviour is and determine if the drop is correct or not.
@kdy1 I can confirm an entry module with the content of:
export * from "https://raw.githubusercontent.com/nats-io/nats.deno/v1.0.0-11/nats-base-client/internal_mod.ts";
does not bundle properly. There are a lot of circular dependencies in this code base. I tried to recreate something minimally reproducible but was unable to. As mentioned above, class Bench should be in the final bundle but it is missing (located here: https://raw.githubusercontent.com/nats-io/nats.deno/v1.0.0-11/nats-base-client/bench.ts)
I also have a bug with "deno bundle" (deno 1.5 regression), it seems to be the same bug.
I was able to reduce the test size:

bug.ts:
import { posix } from "https://deno.land/[email protected]/path/mod.ts";
import { posix as posix74 } from "https://deno.land/[email protected]/path/mod.ts";
console.log( posix.sep, posix74.sep);
the script:
$ ./deno-1.4.6 bundle ./bug.ts bug.js && ./deno-1.4.6 run ./bug.js
$ ./deno-1.5.1 bundle ./bug.ts bug.js && ./deno-1.5.1 run ./bug.js
Originally, I got this bug when I launched "deno bundle" on the project https://github.com/jersou/markdown-explorer-server
$ deno bundle --unstable https://raw.githubusercontent.com/jersou/markdown-explorer-server/main/server.ts mds.js
$ deno run mds.js
error: Uncaught ReferenceError: _posix is not defined
const path3 = isWindows1 ? _win321 : _posix;
^
at file:///home/jer/mds.js:10940:38
I hope it helps
@aricart could you try Deno 1.5.2? The fix was included in the release.
@bartlomieju just did - there are still some symbols that are not being included:
https://raw.githubusercontent.com/nats-io/nats.deno/main/nats-base-client/internal_mod.ts exports JSONCodec and StringCodec, these are not included in the bundle:
❯ deno --version
deno 1.5.2 (71d7482, release, x86_64-apple-darwin)
v8 8.7.220.3
typescript 4.0.5
❯ deno bundle https://raw.githubusercontent.com/nats-io/nats.ws/master/src/mod.ts | grep JSONCodec
Bundle https://raw.githubusercontent.com/nats-io/nats.ws/master/src/mod.ts
Check https://raw.githubusercontent.com/nats-io/nats.ws/master/src/mod.ts
❯ deno upgrade --version 1.4.6
downloading https://github.com/denoland/deno/releases/download/v1.4.6/deno-x86_64-apple-darwin.zip
Version has been found
Deno is upgrading to version 1.4.6
downloading https://github-production-release-asset-2e65be.s3.amazonaws.com/133442384/503f1780-0ae6-11eb-9437-684aaec8a713?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20201109%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20201109T152333Z&X-Amz-Expires=300&X-Amz-Signature=64d05f35ce7efe32bd5acb156129327c1ef77cef8da2a2a29bbec087620b6056&X-Amz-SignedHeaders=host&actor_id=0&key_id=0&repo_id=133442384&response-content-disposition=attachment%3B%20filename%3Ddeno-x86_64-apple-darwin.zip&response-content-type=application%2Foctet-stream
Version has been found
Deno is upgrading to version 1.4.6
Archive: /var/folders/1y/_rk6yz81341g5q8k1vr5nqmw0000gq/T/.tmpyyVYAc/deno.zip
inflating: deno
Upgrade done successfully
❯ deno bundle https://raw.githubusercontent.com/nats-io/nats.ws/master/src/mod.ts | grep JSONCodec
Bundle https://raw.githubusercontent.com/nats-io/nats.ws/master/src/mod.ts
"JSONCodec": internal_mod_ts_1_1["JSONCodec"],
function JSONCodec() {
exports_61("JSONCodec", JSONCodec);
"JSONCodec": true,
"JSONCodec": codec_ts_4_1["JSONCodec"],
export const JSONCodec = __exp["JSONCodec"];