johanholmerin / style9

CSS-in-JS compiler inspired by Meta's stylex
MIT License
570 stars 27 forks source link

Using Next.js _document.js throws error on static export #54

Closed ericmikkelsen closed 3 years ago

ericmikkelsen commented 3 years ago

I have to use _doucment.tsx in Next.js to add the lang attribute to the html element. And it I keep seeing this error on a static export

ModuleNotFoundError: Module not found: Error: Can't resolve '/Users/eric/projects/airtable-code-interview/pages/index.xsrcSRK.css' in '***/***/airtable-code-interview/pages'

Here's my _document.tsx

import Document, { DocumentContext,Html,Head,Main,NextScript } from 'next/document'

class MyDocument extends Document {
  static async getInitialProps(ctx: DocumentContext) {
    const initialProps = await Document.getInitialProps(ctx)

    return initialProps
  }
  render() {
    return (
      <Html>
        <Head />
        <body>
          <Main />
          <NextScript />
        </body>
      </Html>
    )
  }
}

export default MyDocument

And my index.tsx

import Head from 'next/head'
import style9 from 'style9';

const styles = style9.create({
  container: {
    minHeight: '100vh',
    paddingLeft: '.5rem',
    paddingRight: '.5rem',
    display: 'flex',
    flexDirection: 'column',
    justifyContent: 'center',
    alignItems: 'center'
  }
});

export default function Home() {
  return (
    <div className={styles('container')}>
      <Head>
        <title>Create Next App</title>
        <link rel="icon" href="/favicon.ico" />
      </Head>

      <main>
        <h1 className="title">
          Welcome to <a href="https://nextjs.org">Next.js!</a>
        </h1>

        <p className="description">
          Get started by editing <code>pages/index.js</code>
        </p>

        <div className="grid">
          <a href="https://nextjs.org/docs" className="card">
            <h3>Documentation &rarr;</h3>
            <p>Find in-depth information about Next.js features and API.</p>
          </a>

          <a href="https://nextjs.org/learn" className="card">
            <h3>Learn &rarr;</h3>
            <p>Learn about Next.js in an interactive course with quizzes!</p>
          </a>

          <a
            href="https://github.com/zeit/next.js/tree/master/examples"
            className="card"
          >
            <h3>Examples &rarr;</h3>
            <p>Discover and deploy boilerplate example Next.js projects.</p>
          </a>

          <a
            href="https://vercel.com/import?filter=next.js&utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
            className="card"
          >
            <h3>Deploy &rarr;</h3>
            <p>
              Instantly deploy your Next.js site to a public URL with Vercel.
            </p>
          </a>
        </div>
      </main>

      <footer>
        <a
          href="https://vercel.com?utm_source=create-next-app&utm_medium=default-template&utm_campaign=create-next-app"
          target="_blank"
          rel="noopener noreferrer"
        >
          Powered by{' '}
          <img src="/vercel.svg" alt="Vercel Logo" className="logo" />
        </a>
      </footer>
    </div>
  )
}
export const config = { unstable_runtimeJS: false }

(unrelated this is a very cool project)

johanholmerin commented 3 years ago

Could you create a repo with the issue? I wasn't able to reproduce it.


Unrelated thank you

inlineblock commented 3 years ago

I can reproduce this.

inlineblock commented 3 years ago

@johanholmerin - repo https://github.com/inlineblock/testt

johanholmerin commented 3 years ago

This seems to be caused by an issue with Next.js and Webpack 5, and not be specific to style9. Removing the .next directory or switching to Webpack 4 appears to solve it. Disabling caching in Webpack 5 also seems to work, but causes Next.js to freak out.

SukkaW commented 2 years ago

@inlineblock @ericmikkelsen Just a head up, this issue is fixed by #58 and released in style9@0.11.0. If you are using the latest version of Next.js, please check out #61.