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.

I get a 'style._insertCss' is not a function error

See original GitHub issue

Hi, I use react to test with create-react-app v2.1.5 For serverside rendering with scss, css styles.

the app is applied to basic sample on create-react-app. just eject and add code on the Webpack

rules: [
          {
          test: /\.css$/,
          use: [
            'isomorphic-style-loader',
            {
              loader: 'css-loader',
              options: {
                importLoaders: 1
              }
            },
            'postcss-loader'
          ]
        },
///************more code****************///

also App.js

import React, { Component } from 'react';
import logo from './logo.svg';
import s from './App.scss';
import withStyles from 'isomorphic-style-loader/withStyles'


class App extends Component {
  render() {
    return (
      <div className={s.App}>
        <header className={s.Appheader}>
          <img src={logo} className={s.Applogo} alt="logo" />
          <p>
            Edit <code>src/App.js</code> and save to reload.
          </p>
          <a
            className={s.Applink}
            href="https://reactjs.org"
            target="_blank"
            rel="noopener noreferrer"
          >
            Learn React
          </a>
        </header>
      </div>
    );
  }
}

export default withStyles(s)(App);

finally Index.js

import React from 'react';
import ReactDOM from 'react-dom';
// import './index.css';
import StyleContext from 'isomorphic-style-loader/StyleContext'
import App from './App';
import * as serviceWorker from './serviceWorker';

const insertCss = (...styles) => {
  const removeCss = styles.map(style => style._insertCss())
  return () => removeCss.forEach(dispose => dispose())
}

ReactDOM.hydrate(
  <StyleContext.Provider value={{ insertCss }}>
    <App />,
  </StyleContext.Provider>,
  document.getElementById('root')
);

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: http://bit.ly/CRA-PWA
serviceWorker.unregister();
2019-02-26 4 06 57

that’s it, What is miss ? could you please let me know what I miss. thanks

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:16 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
VeXellcommented, Jan 25, 2020

You have this problem because you did not add isomorphic-style-loader to your webpack client build. 1. You should eject your app and update config or 2. install react-app-rewired and add additional config for css or scss rules.

You can play with it here https://github.com/VeXell/ssr/tree/created_with_react_scripts

0reactions
niaogegecommented, Sep 24, 2022

Client needs to be configured,reference resources

  rules: [
      {
        test: /\.css?$/,
        use: [
          "isomorphic-style-loader",
          {
            loader: "css-loader",
            options: {
              importLoaders: 1,
              esModule: false, // !!!important
              modules: {
                localIdentName: "[name]__[local]___[hash:base64:5]",
              },
            },
          },
        ],
      },
    ],
Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome Extension to change Style Elements, insertCSS not ...
I tried using insertCSS in the content.js but read that it will not work from there but should from a popup or background...
Read more >
Chrome Extension to change Style Elements ... - Google Groups
I now get a new error: Error handling response: TypeError: Error in invocation of scripting.insertCSS(scripting.CSSInjection injection, optional function ...
Read more >
tabs.insertCSS() - Mozilla - MDN Web Docs
This is an asynchronous function that returns a Promise (on Firefox only). Syntax. let inserting = browser.tabs.insertCSS( ...
Read more >
tabs.insertCSS()
... function onError(error) { console.log(`Error: ${error}`); } var insertingCSS = browser.tabs.insertCSS(2, {file: "content-style.css"}); ...
Read more >
How to add CSS - W3Schools
Three Ways to Insert CSS. There are three ways of inserting a style sheet: External CSS; Internal CSS; Inline CSS. External CSS. With ......
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