cra-preact icon indicating copy to clipboard operation
cra-preact copied to clipboard

Can't reexport the named export 'renderToString'

Open Drarig29 opened this issue 2 years ago • 1 comments

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

  • react-scripts v : 4.0.3
  • cra-preact v : 0.4.0

Drarig29 avatar Aug 18 '21 11:08 Drarig29

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')

Drarig29 avatar Aug 18 '21 11:08 Drarig29