importDocument,{Head,Main,NextScript} from "next/document";// Import styled components ServerStyleSheetimport{ServerStyleSheet} from "styled-components";exportdefaultclassMyDocument extends Document{static getInitialProps({ renderPage }){// Step 1: Create an instance of ServerStyleSheetconst sheet =newServerStyleSheet();// Step 2: Retrieve styles from components in the pageconst page = renderPage((App)=>(props)=> sheet.collectStyles(<App{...props}/>));// Step 3: Extract the styles as <style> tagsconst styleTags = sheet.getStyleElement();// Step 4: Pass styleTags as a propreturn{...page, styleTags };}
render(){return(<html><Head><title>My app</title>{/* Step 5: Output the styles in the head */}{this.props.styleTags}</Head><body><Main/><NextScript/></body></html>);}}
عندما أعمل build أحصل على هذا الخطأ رغم ان الملف في مجلد pages
3:1 Error: next/document should not be imported outside of pages/_document.js.
See https://nextjs.org/docs/messages/no-document-import-in-page. @next/next/no-document-import-in-page
13:38 Error: Component definition is missing display name react/display-name
السؤال
عبد النور محمد
لدي الملف document.js_
عندما أعمل build أحصل على هذا الخطأ رغم ان الملف في مجلد pages
3:1 Error: next/document should not be imported outside of pages/_document.js. See https://nextjs.org/docs/messages/no-document-import-in-page. @next/next/no-document-import-in-page 13:38 Error: Component definition is missing display name react/display-name
تم التعديل في بواسطة عبد النور محمد1 جواب على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.