How to do peer dependencies when publishing a ReScript npm package?

In npm I can install package foo into devDependencies and list it in peerDependencies so that the user must install foo alongside my library in their package.json.

How is this done with rescript packages?

My package has peer dependencies on two ReScript packages: @rescript/react and rescript-webapi.

The classic JS approach works for rescript-webapi, but for @rescript/react I get errors.

Here’s the repro: https://github.com/tom-sherman/rescript-react-peer-dependency-issue

Steps to reproduce:

cd dependency
npm link
cd ../consumer
npm i
npm link dependency
npm start

Expected:

Built package.

Actual:

FAILED: src/Dependency.cmj

  We've found a bug for you!
  ~/dependency/src/Dependency.res:2:19-21

  1 │ @react.component
  2 │ let make = () => <div> {"Hello"->React.string} </div>
  3 │ 

  The value div can't be found

FAILED: cannot make progress due to previous errors.
1 Like

I had a play with your repro and managed to figure out that the issue is just a missing "reason: { "react-jsx": 3 } from each of the bsconfig.jsons.

I had a read of the docs regarding the reason configuration key and found them a little confusing. It seems to imply that you don’t need the reason config when using Rescript (as opposed to ReasonML):

reason config is enabled by default

and that you should only provide this configuration if you’re using ReasonReact (as opposed to @rescript/react):

To turn on JSX for ReasonReact, specify:

I’m not sure if I’m misreading this or if it’s just older documentation that hasn’t been updated.

2 Likes

Ah nice, thanks! I too was under the impression that the “react-jsx” option wasn’t needed in ReScript, frustrating that both the dependency and the consumer need to set that option.