nx-bun
nx-bun copied to clipboard
bun | task worker runner | nx bun: build does not work and throws an error for node dependencies as bun assumes browser as default
Describe the bug When running nx build <project_name>, 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
- Running
bun build --target=bun ./packages/agenda/src/main.ts --outdir ./dist/packages/agenda
generates the right build - The app was created with the option of "App/Framework" as none