Skip to content

[BUG] Produced code invariably requires node:fs (dead code) #1809

@xzxzzxzxzca

Description

@xzxzzxzxzca

Describe the bug
Let's say we have the simplest possible OCaml program:

let () =
  print_endline "Hello, World!"

Which we compile using jsoo:

(executable
 (name hello)
 (modes js)

 (modules hello)

 (js_of_ocaml
  (flags
    --opt 3
    --enable deadcode
    --enable globaldeadcode
  ))
)

Although the program performs no file operations, the generated code still requires node:fs and contains filesystem functions, even on the highest optimization level, even when asked to eliminate all dead code, even with --profile release.

This is extremely problematic for deployments to React Native platforms, where the module does not exist.

Expected behavior
Filesystem functions should not be included unless actually used.

As an alternative, the module could be loaded lazily.

Versions
ocamlc: 5.2.1
js_of_ocaml: 5.9.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions