Jordan-Hall / nx-bun

https://jordan-hall.github.io/nx-bun/
Other
58 stars 6 forks source link

bun | task worker runner | nx bun: build does not work and throws an error for node dependencies as bun assumes browser as default #18

Open asaph26 opened 9 months ago

asaph26 commented 9 months ago

Describe the bug When running nx build , it runs into the following error.

error: Browser build cannot require() Node.js builtin: "tls". To use Node.js builtins, set target to 'node' or 'bun'

const tls_1 = require("tls");
                      ^
.../node_modules/ioredis/built/connectors/SentinelConnector/index.js:6:23 204

error: Browser build cannot require() Node.js builtin: "dns". To use Node.js builtins, set target to 'node' or 'bun'

const dns_1 = require("dns");

^
.../node_modules/ioredis/built/cluster/ClusterOptions.js:4:23 141

error: Browser build cannot require() Node.js builtin: "tls". To use Node.js builtins, set target to 'node' or 'bun'

const tls_1 = require("tls");

To Reproduce

NX Configuration

{
    "tasksRunnerOptions": {
        "default": {
            "runner": "@nx-bun/task-worker-runner",
            "options": {
                "cacheableOperations": ["lint", "test", "e2e"]
            }
        }
    },
    "extends": "nx/presets/npm.json",
    "$schema": "./node_modules/nx/schemas/nx-schema.json",
    "affected": {
        "defaultBase": "master"
    },
    "cli": {
        "defaultCollection": "@nx-bun/nx"
    },
    "targetDefaults": {
        "lint": {
            "inputs": [
                "default",
                "{workspaceRoot}/.eslintrc.json",
                "{workspaceRoot}/.eslintignore",
                "{workspaceRoot}/eslint.config.js"
            ]
        }
    },
    "pluginsConfig": {
        "@nx/js": {
            "analyzeSourceFiles": true
        }
    }
}

Project compiler options

 "compilerOptions": {
        "outDir": "../../dist/out-tsc",
        "declaration": true,
        "target": "es2022",
        "module": "ES2022",
        "moduleResolution": "node",
        "types": ["bun-types"],
        "esModuleInterop": true,
        "forceConsistentCasingInFileNames": true,
        "skipLibCheck": true,
        "strict": true
    },

Project build config

 "build": {
            "executor": "@nx-bun/nx:build",
            "outputs": ["{options.outputPath}"],
            "options": {
                "entrypoints": ["packages/agenda/src/main.ts"],
                "outputPath": "dist/agenda",
                "tsconfig": "packages/agenda/tsconfig.app.json",
                "smol": false,
                "bun": true,
                "target": "bun"
            }
        },

Changing the target to node/bun has no impact

Expected behavior

Additional context