You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I did same steps as explained in example but got this error :
/Users/user/projcect/node_modules/used-styles/dist/es5/utils.js:39
if (!def.isReady) {
^
TypeError: Cannot read property 'isReady' of undefined
at Object.exports.assertIsReady (/Users/user/projcect/node_modules/used-styles/dist/es5/utils.js:39:14)
at Transform.transform [as _transform] (/Users/user/projcect/node_modules/used-styles/dist/es5/reporters/used.js:37:21)
my code looks like :
importReactfrom'react';importthroughfrom'through';import{renderToNodeStream}from'react-dom/server';import{StaticRouter,matchPath}from'react-router-dom';import{HelmetProvider}from'react-helmet-async';import{ProviderasReduxProvider}from'react-redux';import{ServerStyleSheet}from'styled-components';import{ChunkExtractor}from'@loadable/server';import{createLink,createStyleStream,discoverProjectStyles,}from'used-styles';importMultiStreamfrom'multistream';importHocfrom'components/Common/Hoc';import{readableString}from'./utils/readable';importcreateStorefrom'../../app/config/configureStoreSSR';import{indexHtml}from'./indexHtml';exportasyncfunctionrenderServerSideApp(req,res){constcontext={};consthelmetContext={};/** * Styled component instance * @type {ServerStyleSheet} */constsheet=newServerStyleSheet();try{const{ store, history }=createStore(req.url);/** * A box of components which will load Server app * @returns {*} * @constructor */constServerApp=()=>(<HelmetProvidercontext={helmetContext}><ReduxProviderstore={store}><StaticRouterhistory={history}location={req.url}context={context}><HocrouterProvider="server"/></StaticRouter></ReduxProvider></HelmetProvider>);conststats=require(`${process.cwd()}/build/${process.env.PUBLIC_URL}/loadable-stats.json`);constchunkExtractor=newChunkExtractor({ stats });conststylesLookup=discoverProjectStyles(`${process.cwd()}/build`);// __dirname usually/** * Handle 404 and 301 */if(context.url){returnres.redirect(301,context.url);}if(context.status===404){res.status(404);}const[header,footer]=indexHtml({helmet: helmetContext.helmet,state: store.getState(),});/** * Get styledComponents global styles */constjsx=chunkExtractor.collectChunks(sheet.collectStyles(<ServerApp/>),);constendStream=readableString(footer);res.set({'content-type': 'text/html; charset=utf-8'});res.write([header,'<div id="root">'].join(''));// Pipe that HTML to the responseconstHtmlStream=sheet.interleaveWithNodeStream(renderToNodeStream(jsx));constlookup=awaitstylesLookup;// create a style steamconststyledStream=createStyleStream(lookup,style=>// _return_ link tag, and it will be appended to the stream outputcreateLink(`dist/${style}`),// <link href="dist/mystyle.css />);newMultiStream([styledStream,endStream]).pipe(res);HtmlStream.pipe(.pipe(styledStream,{end: false}).pipe(through(functionwrite(data){this.queue(styledStream);this.queue(data);},asyncfunctionend(){this.queue('</div>');this.queue(chunkExtractor.getScriptTags());this.queue(chunkExtractor.getStyleTags());this.queue(endStream);this.queue(null);res.end();},),);}catch(error){res.status(500).send('Oops, better luck next time!');}}
The text was updated successfully, but these errors were encountered:
That means that const lookup = await stylesLookup; resolves to undefined. And it does. And it's easy to fix it.
However this is intended way to use it:
await stylesLookup;
const styledStream = createStyleStream(
stylesLookup, // use the same variable
Plus please scan styles only once, and better outside of the render function, so they would be ready a bit earlier.
Plus the scan operation is more or less expensive(they all got parsed with PostCSS and analysed), and it's better not to run it frequently.
I did same steps as explained in example but got this error :
my code looks like :
The text was updated successfully, but these errors were encountered: