Closed nineohnine closed 5 years ago
I am using babel-node with your module-loader configuration
Can you elaborate on your setup? In general mixin preact
with react
only works by rewriting (aka aliasing) imports. If you're using babel-node
alone you'll likely need to add a plugin that switches out imports to react
.
yep so I am using this setup in my babelrc from the readme:
{
// ...
"plugins": [
["module-resolver", {
"root": ["."],
"alias": {
"react": "preact-compat",
"react-dom": "preact-compat",
// Not necessary unless you consume a module using `createClass`
"create-react-class": "preact-compat/lib/create-react-class",
// Not necessary unless you consume a module requiring `react-dom-factories`
"react-dom-factories": "preact-compat/lib/react-dom-factories"
}
}]
],
"presets": [
"react"
]
// ...
}
If you're not running Babel on node_modules (most people don't), the aliases set in your Babel config are not applied to those files.
You should use module-alias
instead, which applies to all requires:
https://github.com/developit/preact-compat/issues/299#issuecomment-280499913
I am trying to build a ssr & client side app using preact. I am using babel-node with your module-loader configuration. I am getting errors from inside my dependency that it cannot load resolve react. Is this to be expected ? I can resolve react (preact-compat) from my project files. But when a dependency of my project does it throws. Is this the expected behavior or am i doing something wrong?
Thanks!