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

Panic when using in jest transformer #407

Closed
eelco opened this issue Sep 22, 2020 · 5 comments
Closed

Panic when using in jest transformer #407

eelco opened this issue Sep 22, 2020 · 5 comments

Comments

@eelco
Copy link
Contributor

eelco commented Sep 22, 2020

In jest.config.js:

    transform: {
        "\\.(ts|tsx)$": "./test/esbuild-transformer.js",
    },

test/esbuild-transformer.js (stripped down to a minimal version to reproduce the problem):

const { buildSync } = require("esbuild")
buildSync({})

Result when running jest:

    Panic: interface conversion: interface {} is map[string]interface {}, not []interface {}

    goroutine 20 [running]:
    runtime/debug.Stack(0xc0000a5590, 0x12ed080, 0xc0000a5560)
    	/usr/local/go/src/runtime/debug/stack.go:24 +0x9f
    main.(*serviceType).handleIncomingMessage.func1(0x100000000, 0x12e9d60, 0xc0000a5500, 0xc000042f70)
    	/Users/evan/dev/esbuild/cmd/esbuild/service.go:139 +0x6c
    panic(0x12ed080, 0xc0000a5560)
    	/usr/local/go/src/runtime/panic.go:969 +0x175
    main.(*serviceType).handleIncomingMessage(0xc0000b2360, 0xc00012e090, 0x8a, 0x90, 0x0, 0x0, 0x0)
    	/Users/evan/dev/esbuild/cmd/esbuild/service.go:146 +0x5c9
    main.runService.func2(0xc0000b2360, 0xc00012e090, 0x8a, 0x90, 0xc0000bcab0)
    	/Users/evan/dev/esbuild/cmd/esbuild/service.go:85 +0x50
    created by main.runService
    	/Users/evan/dev/esbuild/cmd/esbuild/service.go:84 +0x1c5
@eelco
Copy link
Contributor Author

eelco commented Sep 22, 2020

Note that this problem occurs in 0.7.2 and not in 0.6.34.

@evanw
Copy link
Owner

evanw commented Sep 22, 2020

I can't reproduce this. Here's what I tried:

$ npm i jest esbuild
$ cat package.json
{
  "dependencies": {
    "esbuild": "0.7.2",
    "jest": "26.4.2"
  }
}
$ mkdir temp
$ cat > test/esbuild-transformer.js 
const { buildSync } = require("esbuild")
buildSync({})
$ touch test.ts
$ node node_modules/.bin/jest
 FAIL  ./test.ts
  ● Test suite failed to run

    Either provide "outfile" or set "write" to false

      1 | const { buildSync } = require("esbuild")
    > 2 | buildSync({})
        | ^
      3 | 

      at node_modules/esbuild/lib/main.js:474:31
      at handleIncomingPacket (node_modules/esbuild/lib/main.js:459:9)
      at readFromStdout (node_modules/esbuild/lib/main.js:413:7)
      at runServiceSync (node_modules/esbuild/lib/main.js:749:3)
      at buildSync (node_modules/esbuild/lib/main.js:643:3)
      at Object.<anonymous> (test/esbuild-transformer.js:2:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.645 s
Ran all test suites.

This crash looks to me like there is a mismatch between the version of esbuild's JavaScript code and the version of esbuild's binary executable. I can reproduce the crash if I install esbuild 0.7.2 and then replace node_modules/esbuild/bin/esbuild with the binary executable from version 0.6.34. The reason why this particular crash is happening is that the binary protocol has been changed.

If you are in this state then the way you installed esbuild means that it was not installed correctly. How did you install esbuild? The officially supported way to install esbuild is npm, but there are many alternative package managers that people have been using.

@evanw
Copy link
Owner

evanw commented Sep 23, 2020

I have just published a new version of esbuild which verifies that the binary and the host code are from the same package version. If that is indeed the problem here, then installing esbuild version 0.7.3 should provide an error message that hopefully gives more information about the problem.

@eelco
Copy link
Contributor Author

eelco commented Sep 23, 2020

Apologies, I extracted the minimal case out of a more complex setup, but did not take into account the surrounding setup (using yarn workspaces), so this might have affected it.

When I installed 0.7.3, the error completely disappeared, but when I downgraded to 0.7.2 again to see if I could still reproduce it, I did get the new error: Cannot start service: No version number from host.

Checking the installed bin/esbuild file it seems it still has 0.7.3 in this case, even though yarn seems happy and updated the lock file. Seeing this is very likely a yarn bug, I’m closing the issue.

Thanks for the fast response!

@eelco eelco closed this as completed Sep 23, 2020
@evanw
Copy link
Owner

evanw commented Sep 23, 2020

Thanks for the additional information. I think this is actually due to PR #91, which was attempting to fix yarn installs. It appears to have been an incorrect fix. I will try reverting that PR to fix this issue.

evanw added a commit that referenced this issue Sep 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants