jsii icon indicating copy to clipboard operation
jsii copied to clipboard

`jsii-rosetta` is incompatible with `esbuild`

Open iliapolo opened this issue 4 years ago • 0 comments

:bug: Bug Report

Affected Languages

The problem is with jsii-rosetta, which is not a jsii module in itself and only available in TypeScript.

General Information

  • JSII Version: 1.50.0 (build d1830a4), typescript 3.9.10
  • Platform: Darwin a483e7b9e4e1.ant.amazon.com 20.6.0

What is the problem?

Ever since https://github.com/aws/jsii/pull/3161, jsii-rosetta can no longer be used from within a esbuild bundle. The problem lies in a dynamic reference to the translate_all_worker.js file that was added in this PR.

https://github.com/aws/jsii/blob/a833a1d2f1335e9447fd5702b9e4f9c6166abe67/packages/jsii-rosetta/lib/translate_all.ts#L34-L36

This type of reference is not picked up by esbuild resulting in the file being missing at runtime.

Verbose Log

Error: Cannot find module '/bundle/translate_all_worker.js'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at MessagePort.<anonymous> (node:internal/main/worker_thread:187:24)
    at MessagePort.[nodejs.internal.kHybridDispatch] (node:internal/event_target:562:20)
    at MessagePort.exports.emitMessage (node:internal/per_context/messageport:23:28)

iliapolo avatar Jan 02 '22 14:01 iliapolo