Skip to content
New issue

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

@nrwl/esbuild:esbuild outdir/outfile overwritten when defined in esbuildOptions #14635

Closed
Schmale97 opened this issue Jan 26, 2023 · 3 comments · Fixed by #14636
Closed

@nrwl/esbuild:esbuild outdir/outfile overwritten when defined in esbuildOptions #14635

Schmale97 opened this issue Jan 26, 2023 · 3 comments · Fixed by #14636
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug

Comments

@Schmale97
Copy link
Contributor

Schmale97 commented Jan 26, 2023

Current Behavior

When using the esbuild executor, I am unable to define my own outfile/outdir as it gets overwritten by the executor. This is causing my builds to fail when I set splitting to true and define and outdir (the executor sets its own outfile - creating a conflict).

My project.json

{
  "name": "dummy-app",
  "$schema": "../../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/dummy-app/src",
  "projectType": "application",
  "targets": {
    "build": {
      "executor": "@nrwl/esbuild:esbuild",
      "outputs": ["{options.outputPath}"],
      "options": {
        "project": "apps/dummy-app/package.json",
        "outputPath": "dist/apps/dummy-app",
        "main": "apps/dummy-app/src/index.ts",
        "tsConfig": "apps/dummy-app/tsconfig.lib.json",
        "assets": ["apps/dummy-app/.env.*"],
        "esbuildOptions": {
          "banner": {
            "js": "import { createRequire } from 'module'; const require = createRequire(import.meta.url);"
          },
          "splitting": true,
          "outdir": "dist/apps/dummy-app/src"
        }
      }
    },
    "lint": {
      "executor": "@nrwl/linter:eslint",
      "outputs": ["{options.outputFile}"],
      "options": {
        "lintFilePatterns": ["apps/dummy-app/**/*.ts"]
      }
    },
    "test": {
      "executor": "@nrwl/jest:jest",
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
      "options": {
        "jestConfig": "apps/dummy-app/jest.config.ts",
        "passWithNoTests": true
      }
    }
  },
  "tags": []
}

And the output is

error: Cannot use both "outfile" and "outdir"

Expected Behavior

I would expect the executor to not add an outfile or outdir if it already exists in the esbuildOptions - and then the build would succeed

I think this is happening due this block in /packages/esbuild/src/executors/esbuild/lib)/build-esbuild-options.ts

if (options.singleEntry && options.bundle) {
    esbuildOptions.outfile = getOutfile(format, options, context);
  } else {
    esbuildOptions.outdir = options.outputPath;
  }

One fix could be

if (!esbuildOptions.outfile && !esbuildOptions.outdir) {
  if (options.singleEntry && options.bundle && !esbuildOptions.splitting) {
      esbuildOptions.outfile = getOutfile(format, options, context);
   } else {
      esbuildOptions.outdir = options.outputPath;
   }
}

GitHub Repo

No response

Steps to Reproduce

  1. Build project with above project.json

Nx Report

Node : 16.16.0
   OS   : darwin arm64
   npm  : 8.11.0
   
   nx : 15.5.3
   @nrwl/angular : Not Found
   @nrwl/cypress : 15.5.3
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.5.3
   @nrwl/esbuild : 15.6.2
   @nrwl/eslint-plugin-nx : 15.5.3
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.5.3
   @nrwl/js : 15.5.3
   @nrwl/linter : 15.5.3
   @nrwl/nest : Not Found
   @nrwl/next : 15.5.3
   @nrwl/node : 15.5.3
   @nrwl/nx-cloud : 15.0.2
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 15.5.3
   @nrwl/react-native : Not Found
   @nrwl/rollup : 15.5.3
   @nrwl/schematics : Not Found
   @nrwl/storybook : 15.5.3
   @nrwl/web : 15.5.3
   @nrwl/webpack : 15.5.3
   @nrwl/workspace : 15.5.3
   @nrwl/vite : Not Found
   typescript : 4.9.4
   ---------------------------------------
   Local workspace plugins:
         undefined
   ---------------------------------------
   Community plugins:
         @nxext/capacitor: 15.2.0
         @nxext/ionic-react: 15.1.0

Failure Logs

error: Cannot use both "outfile" and "outdir"

Error: Build failed with 1 error:
error: Cannot use both "outfile" and "outdir"


### Additional Information

_No response_
@Schmale97 Schmale97 changed the title @nrwl/esbuild:esbuild @nrwl/esbuild:esbuild outdir/outfile overwritten when defined in esbuildOptions Jan 26, 2023
@AgentEnder AgentEnder added the scope: bundlers Issues related to webpack, rollup label Jan 31, 2023
@shellscape
Copy link

Just ran into this today, and it's a royal pain.

@herrKlein
Copy link
Contributor

herrKlein commented Mar 17, 2023

Could this be fixed before 16.0.0 release, I see there is a fix waiting.
I badly need to have multiple outputs and imports using esbuild splitting and creating library chunks.

@github-actions
Copy link

github-actions bot commented May 5, 2023

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants