bloodyowl / rescript-test

A lightweight test framework for ReScript
https://bloodyowl.github.io/rescript-test/
MIT License
78 stars 9 forks source link

Installing `rescript-test` prior to changing `suffix` in `bsconfig.json` #11

Closed dchambers closed 1 year ago

dchambers commented 1 year ago

First of all, thank you so much for taking the time to create this library 🙏.


rescript-test/bin/retest.mjs uses the inferred suffix when loading its own Test module:

yet the compiled output of that Test.res modle appears to depend on the suffix setting within the end-developers bsconfig.json file.

Therefore, if a developer installs rescript-test, finds out that it doesn't support the .bs.js suffixed files that actually contain ES6 import statements (which rescript currently outputs), and then attempts to fix that by changing suffix to .mjs within bsconfig.json, they will instead get this error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/Users/dominic.chambers/dev/proj/node_modules/rescript-test/src/Test.mjs' imported from /Users/dominic.chambers/dev/proj/node_modules/rescript-test/bin/retest.mjs
    at new NodeError (internal/errors.js:322:7)
    at finalizeResolution (internal/modules/esm/resolve.js:308:11)
    at moduleResolve (internal/modules/esm/resolve.js:731:10)
    at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:842:11)
    at Loader.resolve (internal/modules/esm/loader.js:89:40)
    at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
    at Loader.import (internal/modules/esm/loader.js:177:28)
    at importModuleDynamically (internal/modules/esm/translators.js:114:35)
    at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
    at file:///Users/dominic.chambers/dev/proj/node_modules/rescript-test/bin/retest.mjs:42:41 {
  code: 'ERR_MODULE_NOT_FOUND'
}

Likely unbeknownst to the developer, this can actually be mitigated by deleting node_modules\rescript-test, and running yarn or npm install again, at which point it will re-build the Test module using the now appropriate settings within bsconfig.json.

bloodyowl commented 1 year ago

this is due to the fact rescript builds the dependencies/devDependencies once, and then rebuilds your project.

running the rescript -with-deps should fix the issue without having to delete from node_modules