Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run it inside of nextjs ─ is it possible? #61

Closed
matepaiva opened this issue May 13, 2021 · 3 comments
Closed

Run it inside of nextjs ─ is it possible? #61

matepaiva opened this issue May 13, 2021 · 3 comments

Comments

@matepaiva
Copy link

Hi, first of all, thanks for the wonderful job!

I would like to use the mjml components whithin a next.js application, but when I try to run it as a page I get the error:

error - ./node_modules/clean-css/lib/reader/apply-source-maps.js:1:0
Module not found: Can't resolve 'fs'

I tried to disable js at client-side so it would only return HTML, but it doesn't make any difference.

// src/pages/newsletter.js
import MyMjmlComponent from 'components/mjml/MyMjmlComponent';
import { Mjml } from 'mjml-react';

export default function Newsletter() {
  return (
    <Mjml>
      <MyMjmlComponent timeline="hi" />
    </Mjml>
  );
}

export const config = {
  unstable_runtimeJS: false
};

I also could make it work by rendering using the next.js API. It works, but I lose a lot of good features, especially client hot reload on change:

import { render, Mjml } from 'mjml-react';
import { graphql } from 'relay-hooks';
import MyMjmlComponent from 'components/mjml/MyMjmlComponent';
import fetchQuerySSR from 'lib/fetchQuerySSR';

const query = graphql`
  query newsletterQuery {
    timeline(context: HOMEPAGE) {
      ...MyMjmlComponent_data
    }
  }
`;

export default async function newsletter(req, res) {
  const relayData = await fetchQuerySSR(query);

  const { html } = render(
    <Mjml>
      <MyMjmlComponent timeline={relayData.timeline} />
    </Mjml>,
    { validationLevel: 'soft', minify: undefined }
  );

  res.send(html);
}

Do you have any clue what I could do to make it work as a page? :)

Thank you!

@matepaiva matepaiva changed the title Run it inside of nextjs Run it inside of nextjs ─ is it possible? May 13, 2021
@gajus
Copy link

gajus commented Jun 24, 2021

See vercel/next.js#7755 (comment)

@vpontis
Copy link

vpontis commented Jul 17, 2021

This is a duplicate of #52

@daliusd
Copy link
Contributor

daliusd commented Feb 28, 2022

Closed as it is duplicate

@daliusd daliusd closed this as completed Feb 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants