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

Compiled version of the CSS #57

Closed
OmarZeidan opened this issue Aug 6, 2020 · 7 comments
Closed

Compiled version of the CSS #57

OmarZeidan opened this issue Aug 6, 2020 · 7 comments

Comments

@OmarZeidan
Copy link

OmarZeidan commented Aug 6, 2020

Can you please have the CSS compiled instead of being imported from the node_modules

Where:

import 'codemirror/lib/codemirror.css';

And L5

This is causing troubles when we use the library for next.js

<3

jaywcjlove added a commit that referenced this issue Aug 7, 2020
@jaywcjlove
Copy link
Member

@OmarZeidan Upgrade + @uiw/[email protected]

@OmarZeidan
Copy link
Author

@jaywcjlove Thanks but the same error!

Look inside /lib/esm/index.js file of your compiled version, and you will notice

import './codemirror.css';
import './index.css';

Which will def be causing the error for next.js framework and Global CSS dilemma!

@jaywcjlove
Copy link
Member

@OmarZeidan Can you give me an example, let me debug it?

@Gnarus-G
Copy link

Next.js says this, when I try to use the component.

error - ./node_modules/@uiw/react-codemirror/lib/esm/codemirror.css
Global CSS cannot be imported from within node_modules.
Read more: https://err.sh/next.js/css-npm
Location: node_modules/@uiw/react-codemirror/lib/esm/index.js

Is this a good example? Try to render this component.

import Codemirror from "@uiw/react-codemirror";

export default function CodeEditor() {

    function onChange(instance: CodeMirror.Editor, change: CodeMirror.EditorChangeLinkedList[]) {
        console.log('instance :>> ', instance.getValue);
    }

    return <Codemirror
        options={{
            theme: 'monokai',
            keyMap: 'sublime',
            mode: 'jsx',
        }}
        onChange={onChange}
    />
}

@jaywcjlove
Copy link
Member

@Gnarus-G Since codemirror does not support server-side rendering, it is a bit strange to implement. Upgrade + @uiw/[email protected]

import { useEffect, useState } from 'react';

function HomePage() {
  const [comp, setComp] = useState();
  useEffect(() => {
    if (window) {
      import('@uiw/react-codemirror').then((obj) => {
        if (!comp) {
          setComp(obj.default);
        }
      });
    }
  }, []);

  const Comps = comp;
  return (
    <div>
      <div>Welcome to Next.js!</div>
      {Comps && (
        <Comps
          value="const a = 0;"
          options={{
            mode: "jsx",
          }}
        />
      )}
    </div>
  )
}

export default HomePage
$ yarn add @zeit/next-css

Add next.config.js

const withCSS = require('@zeit/next-css');

module.exports = withCSS({
  // Your configurations here
});

@jaywcjlove
Copy link
Member

@Gnarus-G
Copy link

@jaywcjlove Oh man, I appreciate you. I learned a lot from this. Thank you.

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

3 participants