shilangyu / cra-preact

Comfort of CRA + preact without ejecting 🔥
MIT License
27 stars 3 forks source link

Can't reexport the named export 'renderToString' #7

Open Drarig29 opened 3 years ago

Drarig29 commented 3 years ago

Describe the bug

I have this error when I yarn start and yarn build.

Can't reexport the named export 'renderToString' from non EcmaScript module (only default export is available)

This is linked to this comment: https://github.com/preactjs/preact/issues/1399#issuecomment-472561720

To Reproduce Steps to reproduce the behavior:

  1. Install preact: 10.5.14
  2. Install preact-render-to-string: 5.1.19
  3. Try to compile

Expected behavior It should build the project.

Versions

Drarig29 commented 3 years ago

What I did to resolve the issue, but only temporarily, is to add webpack-modules in node_modules/cra-preact/src/(start|build).js.

Like the following:

const hookIntoRequire = require('require-in-the-middle')
+ const WebpackModules = require('webpack-modules')

hookIntoRequire(['react-scripts/config/webpack.config'], configFactory => {
    const config = configFactory('production')

    config.resolve.alias['react'] = 'preact/compat'
    config.resolve.alias['react-dom'] = 'preact/compat'
    config.resolve.alias['react-dom/test-utils'] = 'preact/test-utils'

+    config.plugins.push(new WebpackModules())

    return () => config
})

require('react-scripts/scripts/build')