-
Notifications
You must be signed in to change notification settings - Fork 471
Description
Thank you for filing! Check list:
- Is it a bug? Usage questions should often be asked in the forum instead.
- Concise, focused, friendly issue title & description.
- A minimal, reproducible example.
- OS and browser versions, if relevant.
- Is it already fixed in master? Instructions
Updating from the alpha to 12.0.0-beta.9
causes Deno to break with this error:
We've found a bug for you!
command line
The module or file Pervasives can't be found.
- If it's a third-party dependency:
- Did you add it to the "dependencies" or "dev-dependencies" in rescript.json?
- Did you include the file's directory to the "sources" in rescript.json?
Small example: https://github.com/jderochervlk/rescript-12-beta-deno
Real project: https://github.com/jderochervlk/plex-movie-night
One fix suggested by @nojaf was to was this to the rescript.json
file:
"bsc-flags": [
"-I",
"/FULL_FILE_PATH/node_modules/rescript/lib/ocaml"
]
But this didn't work for me once I needed children dependencies such as webapi, and it would be difficult to maintain across machines and CI.
I think the core issue is that there are a few places in Rescript that expect a certain file structure for module resolution, and Deno doesn't follow that, and in fact can work without even having a node_modules
folder.
This doesn't only impact Deno, there was also a recent bug for pnpm
: #7526, which was closed and is now re-opened.
Instead of using hard-coded references to node_modules
or the location of files, the compiler should be able to use the module resolution for the package manager being used.
For example root.join("node_modules").join(package_name)
is expecting there to be a folder inside of node_modules
with the package name, which may or may not be true on Deno. @rescript/linux-x64
and @rescript/runtime
don't exist there since they aren't directly part of my source code, they are inside of node_modules/.deno
.
rescript/rewatch/src/helpers.rs
Line 105 in e0528c0
pub fn package_path(root: &Path, package_name: &str) -> PathBuf { |
The current way of getting the path to the standard library is complex and does not work with Deno: https://github.com/nojaf/rescript/blob/43097c8ea312df0de21b4f140bb692e0db747f27/compiler/ext/config.ml#L3-L301
One possible solution is to use import.meta.resolve
in some way to get the path for dependencies. It uses the built in ESM module resolution and works across package managers.
import.meta.resolve("@rescript/webapi")
This would mean that somewhere in the Rust compiler code it would need to reach out to node. Perhaps this could be a pre-build step based on the dependencies listed in the rescript.json
file plus the standard library? I think for it to find the standard library correctly that it would have to be added to the exports
field for rescript/package.json
, "./lib/ocaml/*": "./lib/ocaml/*",
.