-
-
Notifications
You must be signed in to change notification settings - Fork 271
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
Always load when used in electron #48
Comments
Hello @vaemc, sure, we will try! Could you please show the console? |
Hello @vaemc. Sorry for the late answer. Could you please provide me a minimal code snippet, so I can reproduce your problem. I have already created an electron app with minimal config and used this library and it works very well so far. Also, we have "users" of this library who are using electron and there were no issues. Thank you! |
@SurenAt93 I've got the same problem and I'm using this electron base. Steps:
Edit: |
Thank you @LiamRiddell. I will check it right now. |
@LiamRiddell you are completely right, monaco.init() never ends. And the problem is that it can't load sources from CDN. The only thing is missing here is error handling during loading sources from cdn, which I will add in the next version. @vaemc @LiamRiddell So, we have already faced this, and there is a solution for that, please read this discussion and let me know if there are still questions. Thank you for your support! |
@SurenAt93 Thanks for taking a look so fast! I was close to solving last night then... since I changed loader config using Nonetheless this is by far cleanest implementation of Monaco, Thanks :) |
Glad to hear that, will keep it open yet; to wait also @vaemc. |
@SurenAt93 Just testing now. I still can't get this working. Here's the config below:
It finds the loader JS file and then just sits loading still. I've tried copying the file into the app |
Okay, so I've managed to find the issue. It HAS to be an
|
Ah, I see. Huh, it takes a long, but now everything is clear. So, two things I need to do in the near future;
@LiamRiddell Again, thank you for your support. |
@SurenAt93 I think your two action points are good idea. I'm currently struggling to try to get underlying Monaco instance from Editor.js
The reason behind it is so people can register themes and languages without having to do lots of heavy lifting. If you're happy I could make PR? |
import React from "react";
import ReactDOM from "react-dom";
import Editor, { monaco } from "@monaco-editor/react";
monaco
.config({
// ...
})
.init()
.then(monacoInstance => {
/* here is the instance of monaco, so you can use the `monaco.languages` or whatever you want */
console.log("Log ::: Monaco ::: ", monacoInstance);
})
.catch(error =>
console.error("An error occurred during initialization of Monaco: ", error)
);
const App = _ => <Editor height="90vh" language="javascript" />;
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement); or, if you really need to use it from inside of component, it's also possible: import React, { useEffect } from "react";
import ReactDOM from "react-dom";
import Editor, { monaco } from "@monaco-editor/react";
const App = _ => {
useEffect(_ => {
monaco
.init()
.then(monacoInstance => {
/* here is the instance of monaco, so you can use the `monaco.languages` or whatever you want */
console.log("Log ::: Monaco ::: ", monacoInstance);
});
}, []);
return <Editor height="90vh" language="javascript" />;
};
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
import { monaco } from "@monaco-editor/react";
monaco
.init()
.then(monacoInstance => {
monacoInstance.editor.defineTheme('my-super-theme', {
// ...
});
}); The same for language creation. Note that |
@SurenAt93 Yep, I've misunderstood the utility. Thanks for clarifying, I've fixed it in my code too :) |
LiamRiddell's Solution #48 (comment) only works (for me), if I disable webSecurity in Electron, or it refuses to load the resources.
|
@5cript are you trying to load Monaco from node_modules? Could you please provide the part of your code where you configure the Monaco? |
electron version 7.1.8 btw. This is basically just copy paste. // in global scope of one of my files.
import Editor, { monaco } from '@monaco-editor/react';
function uriFromPath(_path) {
let pathName = path.resolve(_path).replace(/\\/g, '/');
if (pathName.length > 0 && pathName.charAt(0) !== '/') {
pathName = `/${pathName}`;
}
return encodeURI(`file://${pathName}`);
}
monaco.config({
urls: {
monacoLoader: uriFromPath(
// same result from node_modules. Does not do anything, if i get the path wrong.
path.join(__dirname, '../public/vs/loader.js')
),
monacoBase: uriFromPath(
path.join(__dirname, '../public/vs')
)
}
}); I never tried deploying the application yet. |
I used this tutorial for setup |
Awesome @LiamRiddell method solved my problem! thank you all @suren-atoyan |
I was having the same problem and managed to fix it while also keeping The issue is that Monaco uses an AMD loader, and Electron uses CJS (when I found that the easiest solution is to delete the references to all CJS related properties from the delete window.require;
delete window.exports;
delete window.module;
// Optionally change the loader paths, it will work regardless
// In my case I wanted to copy these files into a local directory
monaco.config({
urls: {
monacoLoader: '/monaco-editor/min/vs/loader.js',
monacoBase: '/monaco-editor/min/vs'
}
});
const App = <Editor /> I found this solution by chance on the Electron website: https://www.electronjs.org/docs/faq#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron |
Thank you for reply @richard-livingston. The problem is that the behavior is different with different electron setups. Some of them work without a hitch, some of them work with additional config (with changed urls), some of them give strange errors. I am wondering what setup/boilerplate do you use? And BTW, @5cript does it help you? |
I have to test that later when I have the chance, but I'm confident that it will. |
I am using create-react-app, electron ({webSecurity: true, nodeIntegration: true}) rescripts (allows rewrite of webpack.config so that node built-ins are not "empty"). I followed this guide: https://www.codementor.io/@randyfindley/how-to-build-an-electron-app-using-create-react-app-and-electron-builder-ss1k0sfer @5cript good luck. |
Worked for me with electron-webpack. But for local files loading, I still disabled |
With electron-webpack it is working fine in dev mode & production on windows. On Ubuntu, it is not working in Dev mode. But working in prod mode
The difference what I found in dev mode was in windows it is trying to load with file:/// URL. But on ubuntu, it is trying to load with localhost:9080. Hence it was failing. The output of path.join(__static, "/vs") is pointing to absolute paths in both Ubuntu& windows
I don't know why in ubuntu monaco is trying to load the resources using localhost server instead of file:/// URI |
TypeError: Cannot set property 'configScriptSrc' of undefined Did you ever make that mistake? In the manner of @LiamRiddell use: electron + typescript
|
hmm, strange. BTW; |
I don't know why this is undefind |
could you please change the version of the library? |
I'm using @monaco-editor/react@3.4.1. |
dev envI am using absolute URL |
Hi brother ,Always load when used in electron,Can't find the reason
The text was updated successfully, but these errors were encountered: