`The module Bytes is an alias for module Stdlib__Bytes, which is missing` error in OCaml 4.14


I am trying to run an .ml file that uses the Bytes module which seems to have existed in the past (OCaml 4.05) on REPL.

However, if I run it on OCaml 4.14 REPL, I am seeing the following error:

The module Bytes is an alias for module Stdlib__Bytes, which is missing

Could anyone provide a hint to fix or solution of this error?


How did you install OCaml? Did you use opam? If so, what is the output of opam switch? For example, on my machine,

$ opam switch
#  switch                                                         compiler                    description
   5.0.0                                                          ocaml-base-compiler.5.0.0   5.0.0
→  default                                                        ocaml.4.14.1                default

Which implies the standard library files should be in the correct directory:

$ ls ~/.opam/default/lib/ocaml/stdlib__Bytes*

Are your files installed correctly?

This is a weird error that should not happen. The Bytes module still exists. Did you check that your environment is consistent and that you don’t have a module named Stdlib? Do you happen to use an .ocamlinit file?

No, I didn’t use it at .ocamlinit. Instead, the .ml script that invokes Bytes.get is loaded by Toploop.use_file on REPL.
One interesting observation is that, before loading the .ml file, if I simply typecheck Bytes.get on REPL and load the .ml file using Toploop.use_file on REPL then it works well.
I will reduce this code so that a reproducible code snippet can be shared.

Yes, I use opam, but the opam is locally configured (opam env prints the directory that is specific to this project).
Interestingly I can find the ./lib/ocaml/stdlib__Bytes.* from the local opam directory as well.

OCaml 4.14.0 or OCaml 4.14.1 ?

Test #show_module Bytes;;
and #show_module Stdlib.Bytes;;

Hi all, I managed to reduce the program into its minimal form! It consists of these four statements on OCaml REPL 4.14.0:

my_desktop: ~/ $ ocaml
OCaml version 4.14.0
Enter #help;; for help.

# #directory "+compiler-libs";;
# #load "ocamlcommon.cma";;
# Env.fold_modules (fun s p md () -> ()) (Some (Longident.Lident "Bytes"))  !Toploop.toplevel_env ();;
- : unit = ()
# Bytes.get;;
Error: The module Bytes is an alias for module Stdlib__Bytes, which is missing

opam list shows the package versions as follows:

# Packages matching: installed
# Name                      # Installed # Synopsis
base-bigarray               base
base-threads                base
base-unix                   base
camlp-streams               5.0.1       The Stream and Genlex libraries for use with Camlp4 and Camlp5
camlp5                      8.00.03     pinned to version 8.00.03
conf-perl                   2           Virtual package relying on perl
conf-perl-ipc-system-simple 3           Virtual package relying on perl's IPC::System::Simple
conf-perl-string-shellquote 3           Virtual package relying on perl's String::ShellQuote
dune                        3.7.1       Fast, portable, and opinionated build system
num                         1.4         The legacy Num library for arbitrary-precision integer and rational arithmetic
ocaml                       4.14.0      The OCaml compiler (virtual package)
ocaml-base-compiler         4.14.0      Official release 4.14.0
ocaml-config                2           OCaml Switch Configuration
ocaml-options-vanilla       1           Ensure that OCaml is compiled with no special options enabled
ocamlfind                   1.9.6       A library manager for OCaml

I reposted this error at ocaml repo’s GitHub Issue here: `The module Bytes is an alias for module Stdlib__Bytes, which is missing` error in OCaml 4.14 · Issue #12271 · ocaml/ocaml · GitHub

Note that the short answer for using compiler-libs within the REPL is to use utop-full (or another not expunged toplevel). Loading compiler-libs a second time in the REPL create two separate instances of the compiler-libs modules which invariably leads to issues.

For anyone interested in this topic: the Github issue also contains some thread about ocamlmktop.