Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option module loading error #161

Open
kswope opened this issue Nov 16, 2023 · 2 comments
Open

Option module loading error #161

kswope opened this issue Nov 16, 2023 · 2 comments

Comments

@kswope
Copy link

kswope commented Nov 16, 2023

Something is weird about the core Option module, when run with just node

but seems to work just fine with create-react-app (webpack I think)

works

Array.at([1, 2, 3], 0)->Console.log

doesn't work

Option.equal(Some(1), Some(1), (v1, v2) => {v1 == v2})->Console.log
[nodemon] starting `node src/Index.bs.js`
(node:21031) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/kevin/Dev/ReScript/rescript-notes/node_modules/@rescript/core/src/Core__Option.bs.js:3
import * as Curry from "rescript/lib/es6/curry.js";
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1195:20)
    at Module._compile (node:internal/modules/cjs/loader:1239:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
    at Module.load (node:internal/modules/cjs/loader:1133:32)
    at Module._load (node:internal/modules/cjs/loader:972:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:168:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:193:25)

If I sneak a "type":"module" into package.js inside @rescript/core package it starts working

@DZakh
Copy link
Contributor

DZakh commented Nov 17, 2023

Try using .bs.mjs suffix. I don't recommend setting type: "module for ReScript packages, since it'll lead to a whole lot of other problems. There's somewhere a post on the forum about it.

@kswope
Copy link
Author

kswope commented Nov 19, 2023

Try using .bs.mjs suffix. I don't recommend setting type: "module for ReScript packages, since it'll lead to a whole lot of other problems. There's somewhere a post on the forum about it.

Its awkward that this is the default for

npx rescript init
  "package-specs": {
    "module": "es6",
    "in-source": true
  },
  "suffix": ".bs.js"

making running with node fail as your first beginner experience

But I still cant figure out what it was only the Option module and not Array module that gave me this error. Something is different between them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants