johanholmerin / style9

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

Plugin does not work with next-contentlayer #69

Closed liby closed 2 years ago

liby commented 2 years ago

style9/next does not seem to work nice with next-contentlayer. When the two plugins are used together, an error is thrown:

Syntax error: Support for the experimental syntax 'importAssertions' isn't currently enabled (3:43): ```js // next.config.js const { withContentlayer } = require("next-contentlayer"); const withTM = require("next-transpile-modules")(["style9"]); const withStyle9 = require("style9/next"); const nextConfig = withContentlayer({ ...withStyle9()(withTM()), }); module.exports = nextConfig; # or module.exports = withTM(withStyle9({})(withContentlayer({}))); # or module.exports = { ...withContentlayer(), ...withStyle9()(withTM()), }; # or function compose(...plugins) { return (options) => { return plugins.reduce((acc, next) => { return next(acc); }, options); }; } module.exports = compose( withContentlayer, withStyle9(), withTM )() # or module.exports = withStyle9()(compose( withContentlayer, withTM )()) ```

I have tried many solutions, all to no avail.

johanholmerin commented 2 years ago

It sounds like you need to enable the Babel importAssertions option:

withStyle9({
  parserOptions: {
    plugins: ['typescript', 'jsx', 'importAssertions'],
  },
})

If the issue remains please add a repo with a reproduction

liby commented 2 years ago

It sounds like you need to enable the Babel importAssertions option:

withStyle9({
  parserOptions: {
    plugins: ['typescript', 'jsx', 'importAssertions'],
  },
})

If the issue remains please add a repo with a reproduction

Thank you. I tested it for a few days and it worked for me. But after adding the pages/_document, I encountered the problem described by #54. Maybe you have any good ideas?

Reproduce:

  1. Create Next.js project

  2. Install style9, next-transpile-modules, next-contentlayer

  3. Update next.config.js

      const { withContentlayer } = require("next-contentlayer");
      const withTM = require("next-transpile-modules")(["style9"]);
      const withStyle9 = require("style9/next");
    
      function compose(...plugins) {
        return (options) => {
          return plugins.reduce((acc, next) => {
            return next(acc);
          }, options);
        };
      }
    
      const nextConfig = {
        reactStrictMode: true,
        swcMinify: true,
      };
    
      module.exports = withStyle9({
        parserOptions: {
          plugins: ["typescript", "jsx", "importAssertions"],
        },
      })(compose(withContentlayer, withTM)(nextConfig));
  4. Update index file to use style9

  5. Create pages/_document uses style9

  6. Add new style attributes and refresh - Fails

    image