aws / aws/jsii-rosetta

`jsii-rosetta` is incompatible with `esbuild`

Open
#3,653 0 comments 0 reactions 0 assignees View on GitHub
bug p2
Dominant language
TypeScript
Stars
30
Forks
22
Avg merge
1h 28m
Merged PRs (30d)
44

Description

## :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](https://github.com/evanw/esbuild/issues/312) picked up by `esbuild` resulting in the file being missing at runtime.

### Verbose Log

```console
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. (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)
```

Contributor guide

Open the contributing guide

Research direction

Start in packages/jsii-rosetta/lib/translate_all.ts at the dynamic reference to translate_all_worker.js, then reproduce the failure by bundling jsii-rosetta with esbuild. Trace how the worker path is resolved at runtime; done means an esbuild bundle can locate and execute translate_all_worker.js without the reported missing-module error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
build-system, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.