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

Web compatible ts package #455

Closed
wants to merge 2 commits into from
Closed

Conversation

jakdan99
Copy link
Collaborator

@jakdan99 jakdan99 commented Jan 31, 2024

The current TS sources don't work on browser targets. They seem to be targeting node. This PR fixes that.

Could not get it working with the tsconfig.json file, so I added and configured Babel to transpile the files into web compatible js files

@Whathecode
Copy link
Member

You mentioned on Slack you got the following error before this change:

Uncaught Error: Dynamic require of "@cachet/carp-common-generated" is not supported

Can you elaborate what this actually means? When did this occur? What is your build environment, etc.? And. How do these changes fix that?

I looked a bit more into potential incompatibility with the browser given the current setup, and with my albeit limited knowledge, it should work as is. The current Kotlin build outputs UMD modules (configured here). The wrappers written in TypeScript also output UMD modules. It should be possible to consume these from the browser. How are you importing the library in React (I believe that's what you were using)? Are you certain you aren't trying to import it as an ES6 module?

The latest version of Kotlin allows outputting ES6 modules, but that is still experimental and would bring along other bigger changes (seemingly it doesn't export namespaces). We could consider compiling to ES6 later, but would first like to understand the problem you are running into better.

@Whathecode
Copy link
Member

Whathecode commented Feb 12, 2024

Rather than this PR, I'm in the process of finding a nicer solution. Pulling in more dependencies like babel should be unnecessary, and makes this project harder to maintain. From all I could read, this should work with latest versions of node, which can compile to ES modules and interop with CommonJS modules (which UMD modules expose).

I'm working on compiling the tests and wrappers/facades as ES modules, but they still import the generated UMD modules. As you can see in ongoing changes, this does mean changing the way import/exports are currently done in the wrappers. But, I think I got the hang of it, so may be able to wrap this up soon.

I'll create a new PR and give a shout here so you can try whether you have more luck with those sources. I have a suspicion it will, since you will then be importing ES modules into an ES project.

@Whathecode
Copy link
Member

Whathecode commented Feb 28, 2024

The alternate approach in #456 turns out to work, so this PR can be abandoned.

@Whathecode Whathecode closed this Feb 28, 2024
@Whathecode Whathecode deleted the feature/fix-dynamic-import-ts branch February 28, 2024 18:15
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

Successfully merging this pull request may close these issues.

2 participants