Skip to content

The esbuild plugin doesn't work flawlessly with tsup #398

Open
@favna

Description

@favna

🐛 The bug

I'm attempting to implement magic-regexp in the project https://github.com/sapphiredev/utilities (draft PR: sapphiredev/utilities#755), however, for some unknown reason the esbuild plugin is giving me compiler errors. Sadly I cannot manage to reproduce the issue in a clean project so it's somehow something very specific with our project. Even if I use the exact same tsup options in a clean project, the issues does not show up in such a project.

The error I currently get is:

X [ERROR] Unexpected token (9:29) [plugin MagicRegExpTransformPlugin]

  This error came from the "onLoad" callback registered here:

    ../../node_modules/esbuild/lib/main.js:1340:8:
X       1340 │         [ERRORawait promise;
           ╵         ]^ 

    at setupPlugins (file:///F:/sapphiredev/utilities/node_modules/unplugin/dist/index.mjs:995:16)
    at async handlePlugins (F:\sapphiredev\utilities\node_modules\esbuild\lib\main.js:1340:9)

Unexpected token (9:29) [plugin MagicRegExpTransformPlugin]

  This error came from the "onLoad" callback registered here:

    ../../node_modules/esbuild/lib/main.js:1340:8:
      1340 │         await promise;
           ╵         ^

    at setupPlugins (file:///F:/sapphiredev/utilities/node_modules/unplugin/dist/index.mjs:995:16)
    at async handlePlugins (F:\sapphiredev\utilities\node_modules\esbuild\lib\main.js:1340:9)

IIFE dist\iife\index.global.js     29.93 KB
IIFE dist\iife\index.global.js.map 70.50 KB
IIFE ⚡️ Build success in 188ms
CJS Build failed
Error: Build failed with 1 error:
error: Unexpected token (9:29)
    at failureErrorWithLog (F:\sapphiredev\utilities\node_modules\esbuild\lib\main.js:1651:15)
    at F:\sapphiredev\utilities\node_modules\esbuild\lib\main.js:1059:25
    at runOnEndCallbacks (F:\sapphiredev\utilities\node_modules\esbuild\lib\main.js:1486:45)
    at buildResponseToResult (F:\sapphiredev\utilities\node_modules\esbuild\lib\main.js:1057:7)
    at F:\sapphiredev\utilities\node_modules\esbuild\lib\main.js:1086:16
    at responseCallbacks.<computed> (F:\sapphiredev\utilities\node_modules\esbuild\lib\main.js:704:9)
    at handleIncomingPacket (F:\sapphiredev\utilities\node_modules\esbuild\lib\main.js:764:9)
    at Socket.readFromStdout (F:\sapphiredev\utilities\node_modules\esbuild\lib\main.js:680:7)
    at Socket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:559:12)
ESM Build failed

I have linked the draft PR with the WIP branch below as opposed to a stackblitz because the issue is very specific to our project it seems.

To reproduce:

  1. Clone the repository
  2. Check out the proper branch
  3. Run yarn install to install dependencies
  4. Build the package that packages/utilities depends on with:
yarn turbo run build --filter "@sapphire/node-utilities" --filter "@sapphire/eslint-config" --filter "@sapphire/prettier-config"
  1. cd into packages/utilites
  2. Run yarn build
  3. Observe the error being thrown

🛠️ To reproduce

sapphiredev/utilities#755

🌈 Expected behaviour

I am able to build my code correctly using tsup with the esbuild plugin

ℹ️ Additional context

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions