Skip to content

Dynamic module import errors #7403

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

Open
CarlOlson opened this issue Apr 24, 2025 · 0 comments
Open

Dynamic module import errors #7403

CarlOlson opened this issue Apr 24, 2025 · 0 comments

Comments

@CarlOlson
Copy link

CarlOlson commented Apr 24, 2025

Doing a dynamic import will fail if the module to be imported as a module alias:

// Demo
  module Utils = await MathUtils

// MathUtils.res
// This causes a failure even if `Something.res` is empty!
module S = Something

Here is a repository demonstrating the bug: https://github.com/CarlOlson/await-module-test

I tried to follow the example here: https://rescript-lang.org/blog/first-class-dynamic-import-support

Here is the output of the build:

$ npm run res:build

> [email protected] res:build
> rescript

>>>> Start compiling
Dependency Finished
rescript: [9/9] src/Demo.cmj
FAILED: src/Demo.cmj

  We've found a bug for you!
  /home/carl/git/rescript-await-module/await-module-test/src/Demo.res:2:24-32

  1 │ let main = async () => {
  2 │   module Utils = await MathUtils
  3 │   let twoPlusTwo = Utils.add(2, 2)
  4 │   Js.log(twoPlusTwo)

  Invalid argument: Dynamic import requires a module or module value that is a file as argument. Passing a value or local module is not allowed.

FAILED: cannot make progress due to previous errors.
>>>> Finish compiling (exit: 1)

The wording is a bit different, but it exists on 12.0.0-alpha.11.

Annotating the type fixes the compiler warning, but optimizes the await away:

// Demo.res
  module Utils: (module type of MathUtils) = await MathUtils

// Demo.res.mjs
  var twoPlusTwo = MathUtils.add(2, 2);

// Expected Demo.res.mjs
  var Utils = await import("./MathUtils.res.mjs");
  var twoPlusTwo = Utils.add(2, 2);
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

1 participant