Hi All,
Very excited to try out the latest preact as a compat with Next.js .
Sandbox link :- https://codesandbox.io/s/823konwnw8?fontsize=14
Used module alias to integrate ;-
const moduleAlias = require('module-alias')
module.exports = () => {
moduleAlias.addAlias('react', 'preact/compat')
moduleAlias.addAlias('react-dom', 'preact/compat')
}
Here is the output error I am getting :-
$ node server.js
internal/modules/cjs/loader.js:605
throw err;
^
Error: Cannot find module 'preact/compat/server'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:603:15)
at Function.Module._resolveFilename (/Users/maruti/projects/test-nextjs/node_modules/module-alias/index.js:43:29)
at Function.Module._load (internal/modules/cjs/loader.js:529:25)
at Module.require (internal/modules/cjs/loader.js:658:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/Users/maruti/projects/test-nextjs/node_modules/next-server/dist/server/render.js:14:18)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
The error is happening beause next.js is importing "react-dom/server" and it is not able to find it.
Good catch! server.js wasn't listed in the files Preact includes when publishing to npm. Fix will go out shortly.
Is the following still the right way to drop-in-replace react with preact using webpack? (not related to next.js).
resolve: {
alias: {
'react': 'preact/compact',
'react-dom': 'preact/compact',
},
},
Yup - though you misspelled it, should be preact/compat! Once the fix is merged SSR will work again with that setup as well.
@developit that stopped working for me in 10.x, I'm opening another issue with repro :)
Most helpful comment
Good catch!
server.jswasn't listed in the files Preact includes when publishing to npm. Fix will go out shortly.