Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

issue with loading babel() in esbuild.plugins[] #8

Open
noahehall opened this issue May 27, 2021 · 2 comments
Open

issue with loading babel() in esbuild.plugins[] #8

noahehall opened this issue May 27, 2021 · 2 comments

Comments

@noahehall
Copy link

noahehall commented May 27, 2021

having issue using this plugin in my esbuild.config.json.

I just copy pasted your example, throws error immediately.

 > node_modules/statuses/index.js:13:20: error: [plugin: babel] /[appdir]/node_modules/statuses/codes.json: Missing semicolon. (2:7)

  1 | {
> 2 |   "100": "Continue",
    |        ^
  3 |   "101": "Switching Protocols",
  4 |   "102": "Processing",
  5 |   "103": "Early Hints",
     13  var codes = require('./codes.json');


                              ~~~~~~~~~~~
   node_modules/esbuild/lib/main.js:756:22: note: This error came from the "onLoad" callback registered here
    756          let promise = setup({                       ^
    at setup (file:///[appdir]/node_modules/esbuild-plugin-babel/src/index.js:36:9)

you can see the error in action by uncommenting this lline

and running npm start

@gavinsharp
Copy link

gavinsharp commented Oct 20, 2021

The issue seems to be that the plugin by default uses an ESBuild filter of /.*/. This will result in it trying to Babel transform all files that ESBuild processes, including any imported JSON files (e.g. codes.json in your example), and Babel does not support transforming JSON directly.

ESBuild filters are parsed using Go's RegExp library, which doesn't support lookbehind assertions, so I hacked around this in my project by passing a custom filter to the plugin in the ESBuild config:

      babel({
        filter: /.*[^j][^s][^o][^n]$/,
      }),

@michelson
Copy link

Hi @gavinsharp , thanks for this plugin,
question: how could we filter many extensions with this regex?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants