Home:ALL Converter>Lazy loading in Preact routes not working

Lazy loading in Preact routes not working

Ask Time:2021-09-22T05:51:37         Author:afsamir

Json Formatter

I'm trying to use lazy loading in preact and this is my code (routes/form-page.js):

import {lazy, Suspense} from 'preact/compat';
const Form = lazy(() => import("../components/form"));

const FormPage = () => {
    const classes = useStyles();

    return (

        <Grid container justifyContent="center" className={classes.root}>
            <Suspense fallback={<Grid item xs={10} className={classes.suspense}>Loading ...</Grid>}>

it's ok in development but in building (running preact build), it returns error:

ERROR Template execution failed: [object Promise]

what is wrong?

Author:afsamir,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/69275925/lazy-loading-in-preact-routes-not-working
rschristian :

With Preact-CLI, suspense is not supported when prerendering. See preact-cli#1359. You can disable prerendering with preact build --no-prerender.\nThere are other methods of code splitting outlined in the project ReadMe, such as using certain directories or by using the async! prefix in your imports.",