We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In a monorepo, importing from different files of a sibling workspace package leads to duplicate code in generated bundle.
Consider this monorepo:
packages/a/1.ts
./shared
packages/a/2.ts
packages/a/shared.ts
packages/b/index.ts
@test/a/1
@test/a/2
then run:
cd packages/b pnpm esr index.ts
The code in shared.ts will execute twice.
shared.ts
Complete minimal reproduction: https://github.com/IlyaSemenov/esbuild-runner-monorepo-duplicate-import
I believe here:
esbuild-runner/src/esbuild.ts
Lines 35 to 38 in 6e5d00b
we can filter externals with something like:
externals
.filter(e => !(pkg.dependencies?.[e] || pkg.devDependencies?.[e]).startsWith("workspace:"))
The text was updated successfully, but these errors were encountered:
For the time being, I'm using a patch for patch-package.
patch-package
Put this under patches/esbuild-runner+2.2.1.patch:
patches/esbuild-runner+2.2.1.patch
# generated by patch-package 6.4.8 on 2022-04-13 10:39:14 # # command: # npx patch-package esbuild-runner # # declared package: # esbuild-runner: 2.2.1 # diff --git a/node_modules/esbuild-runner/lib/esbuild.js b/node_modules/esbuild-runner/lib/esbuild.js index a35df93..0dc08ed 100644 --- a/node_modules/esbuild-runner/lib/esbuild.js +++ b/node_modules/esbuild-runner/lib/esbuild.js @@ -20,6 +20,7 @@ var externals = []; if (fs_1.default.existsSync(pkgPath)) { var pkg = JSON.parse(fs_1.default.readFileSync(pkgPath, { encoding: "utf-8" })); externals = (0, tslib_1.__spreadArray)((0, tslib_1.__spreadArray)([], Object.keys((_a = pkg.dependencies) !== null && _a !== void 0 ? _a : {}), true), Object.keys((_b = pkg.devDependencies) !== null && _b !== void 0 ? _b : {}), true); + externals = externals.filter(e => !(pkg.dependencies?.[e] || pkg.devDependencies?.[e]).startsWith('workspace:')) } exports.loaders = { ".js": "js",
Sorry, something went wrong.
No branches or pull requests
In a monorepo, importing from different files of a sibling workspace package leads to duplicate code in generated bundle.
Consider this monorepo:
packages/a/1.ts
imports./shared
packages/a/2.ts
imports./shared
packages/a/shared.ts
— this import gets duplicated in esbuild-runner bundlepackages/b/index.ts
— imports@test/a/1
and@test/a/2
then run:
The code in
shared.ts
will execute twice.Complete minimal reproduction: https://github.com/IlyaSemenov/esbuild-runner-monorepo-duplicate-import
Suggested workaround
I believe here:
esbuild-runner/src/esbuild.ts
Lines 35 to 38 in 6e5d00b
we can filter
externals
with something like:The text was updated successfully, but these errors were encountered: