I fiddled around with this a bit, and it looks like CRA does some compile-time magic to the JavaScript. It will either import "./logo.svg"
as either a string or an object containing a React component depending on how the import statement is written. It looks like there’s a GitHub issue about it here.
This imports a React component:
import { ReactComponent as Logo } from './logo.svg';
This imports a string:
import logo from './logo.svg';
And this is an error:
import * as LogoSvg from "./logo.svg";
var make = LogoSvg.ReactComponent;
The latter is what BuckleScript compiles to. Even though it’s perfectly valid JavaScript (and should be equivalent to the first statement), CRA doesn’t compile it as expected.
@pewniak747’s workaround is one solution. You can also use %bs.raw
to achieve the same effect:
%bs.raw
{|import {ReactComponent as _Logo} from "./logo.svg"|};
module Logo = {
[@react.component] [@bs.val] external make: unit => React.element = "_Logo";
};