question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invariant Violation in Server-Side Rendering after import css styles

See original GitHub issue

Steps to reproduce

New rails project with webpacker 4.0.0.rc.7 and react-rails from github (master). Only one component:

import React, { Component } from 'react'

import styles from './App.module.css'

class App extends Component {
  render () {
    return (
      <div className={styles.root}>
         APP
      </div>
    );
  }
}

export default App

In view: <%= react_component('App', {}, { prerender: true }) %>

Expected behavior

Prerender html and working fine in browser.

Actual behavior

Encountered error “#<ExecJS::ProgramError: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it’s defined in, or you might have mixed up default and named imports.>” when prerendering App with {}

System configuration

Webpacker version: 4.0.0.rc.7 React-Rails version: master from github Rails version: 5.2.2 Ruby version: 2.6.0


If disable prerender everything working fine. If remove import styles and all styles from className too. I don’t need styles for prerender, maybe I must disable it for ssr? But how?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12

github_iconTop GitHub Comments

6reactions
dachinatcommented, Feb 14, 2019

I found a solution:

screen shot 2019-02-14 at 8 37 55 am
2reactions
bragovocommented, Feb 7, 2019

It’s works fine with webpacker 3.5.5. Problem only with 4.x version.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Target container is not a DOM element - Stack Overflow
The nice thing about putting script at the bottom is that it won't block rendering until script load in case you add React...
Read more >
Server Side Rendering - Loadable Components
Loadable components loads all your scripts asynchronously to ensure optimal performances. All scripts are loaded in parallel, so you have to wait for...
Read more >
Troubleshooting common React Native bugs - LogRocket Blog
This troubleshooting guide shares how to easily find and address common React Native bugs. See common error examples.
Read more >
[Solved]-Warning for importing css in gatsby-Reactjs
You can try this: import * as style from "../styles/home.module.css". https://www.gatsbyjs.com/docs/tutorial/part-two/#-build-a-new-page-using-css-modules.
Read more >
React-router, Redux, server-side rendering : Invariant Violation
React-router, Redux, server-side rendering : Invariant Violation: Browser ... <title>Universal Reacl</title> <link rel="stylesheet" href=".
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found