nx-bun icon indicating copy to clipboard operation
nx-bun copied to clipboard

bun build does not respect target in project.json options object

Open Gorthog opened this issue 7 months ago • 0 comments

Describe the bug Even though bun target is specified in project.json, the following error message still persists:

31 | const tls = __importStar(require("tls"));
                                      ^
error: Browser build cannot require() Node.js builtin: "tls". To use Node.js builtins, set target to 'node' or 'bun'
    at /home/amir/projects/dealzone/node_modules/https-proxy-agent/dist/index.js:31:34

To Reproduce

  1. Add https-proxy-agent to an nx project
  2. Add in project.json build step "target": "bun":
"build": {
      "executor": "@nx-bun/nx:build",
      "outputs": [
        "{options.outputPath}"
      ],
      "defaultConfiguration": "production",
      "options": {
        "outputPath": "dist/apps/proj",
        "tsConfig": "apps/proj/tsconfig.app.json",
        "entrypoints": [
          "apps/proj/src/main.ts"
        ],
        "target": "bun"
      }
    },
  1. Build the project using nx build proj

Expected behavior Build succeeds.

Additional context The fix is adding

  if (options.target) {
    args.push(`--target=${options.target}`);
  }

in here: https://github.com/Jordan-Hall/nx-bun/blob/b8dd4bf3f5fe22bba121859cee29498d0214d330/packages/nx-bun/src/executors/build/executor.ts#L179

I tried creating a PR but I lack permissions.

Gorthog avatar Jul 21 '24 17:07 Gorthog