-
-
Notifications
You must be signed in to change notification settings - Fork 177
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
Global CSS cannot be imported from within node_modules. #440
Comments
Hi @w3ichen vite does the magic in the react client example, but you seem to have a webpack issue. We have a webpack verification example since a couple of month that checks monaco-editor/monaco-languageclient client example can be build with webpack and that the output can be used. You find it here: Best idea for a way forward: Test our webpack example and compare your build instructions to ours. |
Thanks for your help @kaisalmen. module.exports = {
experimental: {
appDir: true,
}
}; Thanks for this amazing library, I finally got it working. |
@w3ichen Greetings
I am also integrating monaco language client to a monaco react app created in next js. But blocked got stuck at this issue can you share what steps have you done to solve this issue? thanks in advance |
Hi @chaitanya71998 , these are the steps I did:
npm i next@latest react@latest react-dom@latest eslint-config-next@latest
# or
yarn add next@latest react@latest react-dom@latest eslint-config-next@latest
experimental: {
appDir: true,
},
export default function Layout({ children }: React.PropsWithChildren<unknown>) {
return (
<html>
<body>{children}</body>
</html>
);
} Doing this, I was able to import |
Thanks @w3ichen @kaisalmen Can you share what things that could be done exactly if we want to configure in next.config.js to resolve CSS issue? |
@chaitanya71998 I did get some blocking dependencies when updating. Mostly, it was some packages not supporting the latest react version. I just did {
"dependencies": {
},
"overrides": {
"next-auth": {
"react": "$react",
"react-dom": "$react-dom"
},
}
} Unfortunately, upgrading all the packages and using |
@w3ichen Greetings, Did you know regarding this? |
Hi @w3ichen and @kaisalmen I used this next.config.js and the server started without any errors. But after using monco language client as import i was getting the below error. For reference: // package.json
dependencies:{
"monaco-editor": "^0.34.1",
"monaco-languageclient": "4.0.1",
"next": "^12.1.0",
"next-transpile-modules": "9.0.0",
"vscode": "npm:@codingame/[email protected]",
"vscode-ws-jsonrpc": "2.0.1",
}
"resolutions": {
"vscode-languageserver-types": "3.17.2"
} // next.config.js
//@ts-nocheck
const withTM = require("next-transpile-modules")([
// `monaco-editor` isn't published to npm correctly: it includes both CSS
// imports and non-Node friendly syntax, so it needs to be compiled.
"monaco-editor",
])
module.exports = withTM({
reactStrictMode: true,
swcMinify: true,
webpack: webpackConfig => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
webpackConfig.experiments.topLevelAwait = true
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return webpackConfig
},
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},
}) // Monaco editor file
import Spinner from "@components/Spinner"
import Editor from "@monaco-editor/react"
import { CloseAction, ErrorAction, MessageTransports, MonacoLanguageClient, MonacoServices } from "monaco-languageclient"
import normalizeUrl from "normalize-url"
import { useEffect, useMemo } from "react"
import { WebSocketMessageReader, WebSocketMessageWriter, toSocket } from "vscode-ws-jsonrpc"
export type MonacoEditorPropsType = {
path: string
code: string
setCode: (newCode: string) => void
editorOptions: any
}
export function createUrl(hostname: string, port: string, path: string): string {
const protocol = location.protocol === "https:" ? "wss" : "ws"
return normalizeUrl(`${protocol}://${hostname}:${port}${path}`)
}
function createLanguageClient(transports: any) {
return new MonacoLanguageClient({
name: "Sample Language Client",
clientOptions: {
// use a language id as a document selector
documentSelector: ["java"],
// disable the default error handler
errorHandler: {
error: () => ({ action: ErrorAction.Continue }),
closed: () => ({ action: CloseAction.DoNotRestart }),
},
},
// create a language client connection from the JSON RPC connection on demand
connectionProvider: {
get: () => {
return Promise.resolve(transports)
},
},
})
}
function createWebSocket(url: string) {
const webSocket = new WebSocket(url)
webSocket.onopen = () => {
const socket = toSocket(webSocket)
const reader = new WebSocketMessageReader(socket)
const writer = new WebSocketMessageWriter(socket)
const languageClient = createLanguageClient({
reader,
writer,
})
languageClient.start()
reader.onClose(() => languageClient.stop())
}
}
const MonacoEditorWrapper = (props: MonacoEditorPropsType): JSX.Element => {
const { path, code, setCode, editorOptions } = props
const getLatestCode = (code: string) => {
return typeof code === "string" ? JSON.parse(code) : code
}
const hostname = "localhost"
const urlPath = ""
const port = "4000"
const url = useMemo(() => createUrl(hostname, port, urlPath), [hostname, port, urlPath])
useEffect(() => {
// register Monaco languages
const monaco = require("monaco-editor/esm/vs/editor/editor.api")
monaco.languages.register({
id: "java",
extensions: [".java"],
aliases: ["JAVA", "java"],
mimetypes: ["application/text"],
})
// install Monaco language client services
// MonacoServices.install()
createWebSocket(url)
}, [])
return (
<Editor
...editorProps
/>
)
}
export default MonacoEditorWrapper Not knowing where i am missing? |
@chaitanya71998 Are you getting this error from loading the monaco editor and not the monaco-languageclient? |
I am getting it after importing monaco-languageclient in editor file i shared above. Did the above steps worked for you with monaco react? |
Hi @chaitanya71998 I am not familiar with Next.js, but these issues seem to be related to general code assembly/bundling especially inconsistent configuration regarding commonjs/esm modules. Have you checked our troubleshooting section? https:/TypeFox/monaco-languageclient#troubleshooting This should help you avoid some common pitfalls. With regard to our react our example is just that an example. https:/suren-atoyan/monaco-react can be used with monaco-languageclient it is also mentioned in the Troubleshooting section. |
@chaitanya71998 I tried with the "next-transpile-modules" of
So const withTM = require("next-transpile-modules")(["monaco-languageclient"])
module.exports = withTM({ }) In NextJS 13, module.exports = {
transpilePackages: ["monaco-languageclient"],
}; |
I upgraded from
monaco-languageclient==0.13.1-next.9
tomonaco-languageclient==4.0.1
, and it's failing to run.The issue appears to come from
monaco-editor
'sactionbar.js
file where this CSS file is imported:import './actionbar.css';
This is currently an open issue on monaco-editor: microsoft/monaco-editor#886
I was following the react-client example by @kaisalmen. I'm wondering how they got it to work since monaco-editor isn't importing for me. Any help would be greatly appreciated, thanks!
Code
Error
(node:33782) [DEP_WEBPACK_MODULE_ISSUER] DeprecationWarning: Module.issuer: Use new ModuleGraph API (Use `node --trace-deprecation ...` to show where the warning was created) error - ./node_modules/monaco-editor/esm/vs/base/browser/ui/actionbar/actionbar.css Global CSS cannot be imported from within node_modules. Read more: https://nextjs.org/docs/messages/css-npm Location: node_modules/monaco-editor/esm/vs/base/browser/ui/actionbar/actionbar.js
My NextJS App Versions
The text was updated successfully, but these errors were encountered: