Coder Social home page Coder Social logo

Comments (22)

jaywcjlove avatar jaywcjlove commented on July 21, 2024 3

Example: https://codesandbox.io/s/nextjs-example-react-md-editor-qjhn7?file=/pages/index.js
Example: @uiwjs/next-remove-imports/example
Example: https://next-remove-imports-example.vercel.app

from react-textarea-code-editor.

jaywcjlove avatar jaywcjlove commented on July 21, 2024 1

@MariaSolOs Tested, the style can't automatically load the rollback code.

from react-textarea-code-editor.

JM-delatorre avatar JM-delatorre commented on July 21, 2024 1

Im using the same example posted in the Readme, for working with the last version of Nextjs using app routing, and doesnt work it gives me the same error of modules

./node_modules/@uiw/react-textarea-code-editor/cjs/utils.js:10:14
Module not found: ESM packages (rehype) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/@uiw/react-textarea-code-editor/cjs/index.js
./src/app/translate/page.tsx

from react-textarea-code-editor.

jamesmurdza avatar jamesmurdza commented on July 21, 2024 1

@JM-delatorre Thanks for your comment, that helped me. I added "use client" to the top of the file and it worked.

from react-textarea-code-editor.

jaywcjlove avatar jaywcjlove commented on July 21, 2024

@codeXLinkX

Open in CodeSandbox

npm install next-remove-imports
npm install @uiw/[email protected]
// next.config.js
const removeImports = require("next-remove-imports")();
module.exports = removeImports({
  experimental: { esmExternals: true }
});
import React from "react";
import dynamic from "next/dynamic";
import "@uiw/react-textarea-code-editor/dist.css";

const CodeEditor = dynamic(
  () => import("@uiw/react-textarea-code-editor").then((mod) => mod.default),
  { ssr: false }
);

function HomePage() {
  const [code, setCode] = React.useState(
    `function add(a, b) {\n  return a + b;\n}`
  );
  return (
    <div>
      <CodeEditor
        value={code}
        language="js"
        placeholder="Please enter JS code."
        onChange={(evn) => setCode(evn.target.value)}
        padding={15}
        style={{
          fontSize: 12,
          backgroundColor: "#f5f5f5",
          fontFamily:
            "ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace"
        }}
      />
    </div>
  );
}

export default HomePage;

from react-textarea-code-editor.

jaywcjlove avatar jaywcjlove commented on July 21, 2024

uiwjs/react-md-editor#52 (comment)

from react-textarea-code-editor.

codeXLinkX avatar codeXLinkX commented on July 21, 2024

This line still seems to be problematic: import "@uiw/react-textarea-code-editor/dist.css"; causing following error:

error - ../../@uiw/react-textarea-code-editor/dist.css
Global CSS cannot be imported from files other than your Custom <App>. Due to the Global nature of stylesheets, and to avoid conflicts, Please move all first-party global CSS imports to pages/_app.js. Or convert the import to Component-Level CSS (CSS Modules).
Read more: https://nextjs.org/docs/messages/css-global

If I remove that line, I still get another error:

error - ../../@uiw/react-textarea-code-editor/cjs/utils.js:1:0
Module not found: ESM packages (rehype) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals

Import trace for requested module:
./.././@uiw/react-textarea-code-editor/cjs/index.js

If I change experimental: { esmExternals: true } to experimental: { esmExternals: "loose" } while excluding import "@uiw/react-textarea-code-editor/dist.css";, then errors are gone but then the code in textarea doesn't get highlighted.

from react-textarea-code-editor.

jaywcjlove avatar jaywcjlove commented on July 21, 2024

@codeXLinkX Upgrade @uiw/[email protected]

from react-textarea-code-editor.

codeXLinkX avatar codeXLinkX commented on July 21, 2024

Do I still need to keep dist.css import after upgrading to 1.4.7? Because I still get

error - ../../@uiw/react-textarea-code-editor/dist.css
Global CSS cannot be imported from files other than your Custom <App>. Due to the Global nature of stylesheets, and to avoid conflicts, Please move all first-party global CSS imports to pages/_app.js. Or convert the import to Component-Level CSS (CSS Modules).
Read more: https://nextjs.org/docs/messages/css-global

after this change:

const removeImports = require("next-remove-imports")();
module.exports = removeImports({
  experimental: { esmExternals: true },
  webpack5: true,
  ...
});

from react-textarea-code-editor.

jaywcjlove avatar jaywcjlove commented on July 21, 2024

@codeXLinkX Example: https://codesandbox.io/embed/react-textarea-code-editor-example-nextjs-gdzlw?fontsize=14&hidenavigation=1&theme=dark

from react-textarea-code-editor.

codeXLinkX avatar codeXLinkX commented on July 21, 2024

I wonder if the example only works because the css was imported in a file under the /pages folder. I am importing it outside /pages so it probably doesn't run in the server side.

from react-textarea-code-editor.

jaywcjlove avatar jaywcjlove commented on July 21, 2024

I'm not sure what you mean.
@codeXLinkX

from react-textarea-code-editor.

MariaSolOs avatar MariaSolOs commented on July 21, 2024

For my own learning: @jaywcjlove could you please explain why the following next.config is needed?

const removeImports = require("next-remove-imports")();
module.exports = removeImports({
  experimental: { esmExternals: true }
});

from react-textarea-code-editor.

jaywcjlove avatar jaywcjlove commented on July 21, 2024

The next-remove-imports plugin removes the css files(in node_modules) introduced in the package, and nextjs(CSS Imported by a Dependency) will not report an error.

@MariaSolOs

from react-textarea-code-editor.

MariaSolOs avatar MariaSolOs commented on July 21, 2024

@jaywcjlove Thank you for the quick reply! However, it still unclear to me why the esmExternals option is needed. From this Next PR it seems like this package should have an exports field in its package.json...?

from react-textarea-code-editor.

jaywcjlove avatar jaywcjlove commented on July 21, 2024

@MariaSolOs yes i didn't think about adding

  "main": "cjs/index.js",
  "module": "esm/index.js",
"exports": {
  ".": {
    "import": "./esm/index.js",
    "require": "./cjs/index.js"
  },
  "./index": {
    "import": "./esm/index.js",
    "require": "./cjs/index.js"
  }
  ".": {
    "import": "./esm/index.js",
    "require": "./cjs/index.js"
  },
  "./shortcuts": {
    "import": "./esm/shortcuts.js",
    "require": "./cjs/shortcuts.js"
  },
  "./styles": {
    "import": "./esm/styles.js",
    "require": "./cjs/styles.js"
  },
  "./SelectionText": {
    "import": "./esm/SelectionText.js",
    "require": "./cjs/SelectionText.js"
  },
  "./utils": {
    "import": "./esm/utils.js",
    "require": "./cjs/utils.js"
  }
}

"main": "cjs/index.js",
"module": "esm/index.js",
"scripts": {

from react-textarea-code-editor.

MariaSolOs avatar MariaSolOs commented on July 21, 2024

@jaywcjlove Yeah I think that adding that "exports" field should avoid the need of having experimental: { esmExternals: true }.

from react-textarea-code-editor.

bombillazo avatar bombillazo commented on July 21, 2024

Is @v1.4.4 required to work on Next.js? We are using the latest version with next using dynamic import but the styling in the text area does not work at all. :/

Nevemind

I was missing this in my imports:

import "@uiw/react-textarea-code-editor/dist.css";

the example should add this

from react-textarea-code-editor.

jaywcjlove avatar jaywcjlove commented on July 21, 2024

@JM-delatorre Example: https://github.com/uiwjs/next-remove-imports/tree/main/example

from react-textarea-code-editor.

JM-delatorre avatar JM-delatorre commented on July 21, 2024

Im not sure what is the problem, but i re installed the two packages without the versioning tag, and in the component that i am working on i specified that is a client and not a server component. I solved it this way but im not sure why it works.

btw thanks for the fast response.

from react-textarea-code-editor.

TravisHi avatar TravisHi commented on July 21, 2024

Using "next": "13.4.13",

I also had to add: transpilePackages: ["react-textarea-code-editor"],

to my nextConfig object

from react-textarea-code-editor.

jamespsterling avatar jamespsterling commented on July 21, 2024

Using "next": "13.4.13",

I also had to add: transpilePackages: ["react-textarea-code-editor"],

to my nextConfig object

I had to do '@uiw/react-textarea-code-editor' and it worked with v3

from react-textarea-code-editor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.