Skip to content

Export as ES module#652

Open
shirte wants to merge 15 commits into
rdkit:masterfrom
shirte:export-es-module
Open

Export as ES module#652
shirte wants to merge 15 commits into
rdkit:masterfrom
shirte:export-es-module

Conversation

@shirte

@shirte shirte commented Jun 7, 2026

Copy link
Copy Markdown

The aim of this pull request was to enable importing rdkit-js with modern ES syntax:

import initRDKitModule from "@rdkit/rdkit"

The code in this package was simplified by combining code and types in typescript files. These files are compiled via tsup to a CommonJS module (for legacy projects) as well as a ES module (see tsup.config.ts). The package.json file specifies which version is served.

The ES version does not write initRDKitModule to the global window object and it does not require copying wasm files (e.g. see changes in the nextjs example). Also it allows importing RDKit directly without going through a complicated initialization routine:

import { RDKit } from "@rdkit/rdkit/es"

The path "@rdkit/rdkit/es" is used for backwards compatibility. Also, if the bundler doesn't support top-level await, rdkit-js can still be imported using the normal import path "@rdkit/rdkit". The react example project was adapted to demonstrate the resulting benefits.

Building the webassembly wrapper with the Dockerfile doesn't work for the 2026 releases anymore (also without the changes in this pull request). Building older RDKit versions still works:

RDKIT_DASH_VERSION="2025_03_1" \
  SEMVER_VERSION="1.0.0-test" \
  EMSDK_VERSION="3.1.70" \
  BETA="false" bash scripts/build_rdkitjs.sh

Minor fixes:

  • remove duplicate build instructions in build_rdkitjs.sh
  • use local version of "@rdkit/rdkit" in example projects to simplify development
  • simplify importing rdkit-js (and its types) in example projects
  • add missing packages and remove unused packages in example projects
  • fix a race condition in the nextjs example
  • update typescript to version 5 to allow export type * from ...
  • enable passing EMSDK_VERSION to build script

shirte added 15 commits June 1, 2026 21:23
To avoid interfering with unit tests in the Dockerfile, the ES version
is generated alongside the original CommonJS version.
Provide entrypoints for CommonJS (suitable for old code) and ES (modern
javascript). 

Use top-level await in the ES version to enable the user to import the
RDKit object using `import {RDKit } from "@rdkit/rdkit"`. Since CommonJS
doesn't allow top-level await, the corresponding entrypoint skips this.

Use typescript files (ts) to combine .js & .d.ts files and therefore
simplify the wrapper code.
Move type declarations into this folder. Use a placeholder file for
RDKit_minimal_esm.js to avoid errors in the code editor. When the
webassembly wrapper is generated, it will overwrite the placeholder
file.

Add a gitignore file that avoids tracking generated files.
Move tsconfig.json to root directory.

Create multiple tsconfig files for the CommonJS and ES entrypoints.

Upgrade typescript to version 5 to support `import type * from ...`.
Use "file:../.." for the @rdkit/rdkit dependency to make sure that the 
local version will be used. This simplifies development and testing.
Avoid copying files from the rdkit-js dist directory (and let the 
bundler do that).

Import initRDKitModule instead of using window.initRDKitModule.

Simplify statements importing types from "@rdkit/rdkit".
Disable telemetry in nextjs example. This also avoids the error message
"npm error This command does not support workspaces." when running "npm
run dev".

Avoid copying wasm files in nextjs configuration.
Add dependency @rdkit/rdkit (pointing to local version).
Demonstrate the new `import { RDKit } from "@rdkit/rdkit/es"` mechanism 
and simplify the RDKit loading procedure.

Remove unused dependency bulma-collapsible.

Add missing webpack dev dependency.

Add .gitignore file.
Rename example "vue" to "vue-example" to avoid conflicts when running 
`npm install` (since "vue" is also the name of the UI library).*

Add missing dependency hex-rgb.

Import initRDKitModule instead of using window.initRDKitModule.

Simplify type import statements.
Setting rdkitLoaded to true and calling draw() afterwards lead to a race
condition, because setState already rerenders the UI. Removing the
draw() call simplifies the code and avoids the warning in the console.
@shirte shirte requested a review from MichelML as a code owner June 7, 2026 04:59
@vercel

vercel Bot commented Jun 7, 2026

Copy link
Copy Markdown

@shirte is attempting to deploy a commit to the Valence Labs Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant