So I have been trying to upgrade my projects to Rescript v12 from v11. I’ve created a new project but still see the same issue.
package.json:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"rescript": "^12.0.1"
}
}
rescript.json:
{
"name": "test",
"sources": [
{
"dir": "src",
"subdirs": true
}
]
}
src/Index.res:
Console.log(Some(1)->Option.map(x => x + 1))
I encounter this issue:
❯ node src/Index.js
file:///tmp/test/node_modules/@rescript/runtime/lib/js/Stdlib_Option.js:3
let Stdlib_JsError = require("./Stdlib_JsError.js");
^
ReferenceError: require is not defined in ES module scope, you can use import instead
This file is being treated as an ES module because it has a '.js' file extension and '/tmp/test/node_modules/@rescript/runtime/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///tmp/test/node_modules/@rescript/runtime/lib/js/Stdlib_Option.js:3:22
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:514:37)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:425:47)
at loadESMFromCJS (node:internal/modules/cjs/loader:1578:24)
at Module._compile (node:internal/modules/cjs/loader:1743:5)
at Object..js (node:internal/modules/cjs/loader:1893:10)
at Module.load (node:internal/modules/cjs/loader:1481:32)
at Module._load (node:internal/modules/cjs/loader:1300:12)
at TracingChannel.traceSync (node:diagnostics_channel:328:14)
at wrapModuleLoad (node:internal/modules/cjs/loader:245:24)
Node.js v24.11.1
If I set package specs to es6 and use type module in my project package.json, it runs.
Is the runtime broken with commonjs or am I missing something?