Comments (22)
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.
@MariaSolOs Tested, the style can't automatically load the rollback code.
from react-textarea-code-editor.
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.
@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.
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.
uiwjs/react-md-editor#52 (comment)
from react-textarea-code-editor.
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.
@codeXLinkX Upgrade @uiw/[email protected]
from react-textarea-code-editor.
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.
@codeXLinkX Example: https://codesandbox.io/embed/react-textarea-code-editor-example-nextjs-gdzlw?fontsize=14&hidenavigation=1&theme=dark
from react-textarea-code-editor.
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.
I'm not sure what you mean.
@codeXLinkX
from react-textarea-code-editor.
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.
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.
from react-textarea-code-editor.
@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.
@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"
}
}
react-textarea-code-editor/package.json
Lines 5 to 7 in 7e75adf
from react-textarea-code-editor.
@jaywcjlove Yeah I think that adding that "exports"
field should avoid the need of having experimental: { esmExternals: true }
.
from react-textarea-code-editor.
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.
@JM-delatorre Example: https://github.com/uiwjs/next-remove-imports/tree/main/example
from react-textarea-code-editor.
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.
Using "next": "13.4.13",
I also had to add: transpilePackages: ["react-textarea-code-editor"],
to my nextConfig
object
from react-textarea-code-editor.
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)
- How To Display Programming Language Select Button HOT 1
- bundle size HOT 2
- how to do command enter and preventing enter from being sent to code editor? HOT 7
- Auto comment selection HOT 2
- Is `font-family: inherit;` in `.w-tc-editor` required? HOT 2
- JSON Highlighting of Value the same as the Name when a string HOT 2
- [Fix] Shift+Tab on single line removes starting tab HOT 3
- Add the ability to highlight individual lines HOT 2
- Pressing the tab key on a readonly textarea causes a tab in the value HOT 1
- Disable prop HOT 2
- Unable to access ref on CodeEditor using NextJS dynamic HOT 2
- chinese input error HOT 2
- [Feature Request] CSV support HOT 3
- CTRL + Z | Undo HOT 2
- gray color on text highlight HOT 4
- Can I show line numbers ? HOT 1
- Can I show line numbers ? HOT 2
- How to import `TextareaCodeEditorProps` in v3 +? HOT 2
- Module not found: Can't resolve 'devlop' HOT 3
- more customisable padding HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-textarea-code-editor.