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

Monaco Editor Stuck At Loading Screen !!! #58

Closed
ghost opened this issue Mar 2, 2020 · 25 comments
Closed

Monaco Editor Stuck At Loading Screen !!! #58

ghost opened this issue Mar 2, 2020 · 25 comments

Comments

@ghost
Copy link

ghost commented Mar 2, 2020

No description provided.

@suren-atoyan
Copy link
Owner

Could you please provide a little bit more information? Do you use Electron? If yes, please check this discussion.

@ghost
Copy link
Author

ghost commented Mar 4, 2020

But the problem is I don't have a public file in my config !!

@suren-atoyan
Copy link
Owner

Okay, and what you have? To help you I must know the details. As I understand, you use Electron, do you use CRA? In which way are they integrated? Is there a code snippet, github (or other) repo to see the implementation?

Thank you.

@ghost
Copy link
Author

ghost commented Mar 9, 2020

I dont use CRA.
I am using this template :
https://github.com/HendrixString/adobe-cep-react-create
I am making an extension for adobe after effects !!!

@suren-atoyan
Copy link
Owner

suren-atoyan commented Mar 9, 2020

As I am not able to reproduce it in my local machine I can guess two scenarios in which it will not work.

  1. I guess, In the template you shared, it's not possible to load sources from CDN. This library loads monaco sources from CDN by default, so, first, you need to configure it, and load sources from your local files. You can read more detailed about it in the discussion I have already shared earlier.

  2. Monaco uses workers, and does lots of stuff under the hood; maybe the execution environment used inside of Adobe is not compatible with it.

@ghost
Copy link
Author

ghost commented Mar 9, 2020

I couldn't find any solution . I have tried everything !!!

@ghost
Copy link
Author

ghost commented Mar 9, 2020

If u can configure it for me and provide some code snippets it would be very helpful.
I guess there is some problem with the build scripts of the Template !!

@ghost
Copy link
Author

ghost commented Mar 9, 2020

I dont think it is the problem of adobe's execution environment . As it works in the dev build( only with the monaco editor webpack plugin).But does not work in the production build - Does not work even with the Monaco editor webpack plugin.

Any help is highly appreciated .

@ghost
Copy link
Author

ghost commented Mar 15, 2020

Can SomeOne Please Provide a Solution !!!

@OwenMelbz
Copy link

Steps to reproduce:

  • git clone --depth 1 --single-branch https://github.com/electron-react-boilerplate/electron-react-- boilerplate.git monaco-bug
  • cd monaco-bug
  • yarn
  • yarn add @monaco-editor/react
  • yarn add monaco-editor-webpack-plugin
  • Update configs/webpack.config.renderer.dev.babel.js and add new MonacoWebpackPlugin() into the plugins array
  • Update app/components/Home.tsx to:
import React from 'react';
import Editor from '@monaco-editor/react';

export default () => <Editor height="90vh" language="javascript" />;
  • Run yarn dev

Then you just end up with...

Hello_Electron_React_

@ghost
Copy link
Author

ghost commented Mar 19, 2020

I am not using electron

@ghost
Copy link
Author

ghost commented Mar 19, 2020

I am using this template to build Adobe cep extensions
https://github.com/HendrixString/adobe-cep-react-create

@ghost
Copy link
Author

ghost commented Mar 19, 2020

If someone could help me it would be great !!!

@suren-atoyan
Copy link
Owner

Steps to reproduce:

  • git clone --depth 1 --single-branch https://github.com/electron-react-boilerplate/electron-react-- boilerplate.git monaco-bug
  • cd monaco-bug
  • yarn
  • yarn add @monaco-editor/react
  • yarn add monaco-editor-webpack-plugin
  • Update configs/webpack.config.renderer.dev.babel.js and add new MonacoWebpackPlugin() into the plugins array
  • Update app/components/Home.tsx to:
import React from 'react';
import Editor from '@monaco-editor/react';

export default () => <Editor height="90vh" language="javascript" />;
  • Run yarn dev

Then you just end up with...

Hello_Electron_React_

Hello @OwenMelbz, let me check.

@suren-atoyan
Copy link
Owner

@OwenMelbz you don't need steps 5 and 6. The problem is that the library tries to download sources from CDN, which in this setup isn't allowed. Please read this discussion to see how you can download monaco from node_modules or from other local places.

@OwenMelbz
Copy link

Hey, I had eventually got through that and got it working :) so an example component that works for my specific setup was...

// webpack.config.js

import MonacoEditorWebpackPlugin from 'monaco-editor-webpack-plugin';

module.exports = {
    // ..... blah,
    plugins: [
        new MonacoEditorWebpackPlugin(),
    ]
}
// SomeComponent.js

import React from 'react';
import path from 'path';
import Editor, { monaco } from '@monaco-editor/react';

const 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(
        path.join(__dirname, '../node_modules/monaco-editor/min/vs/loader.js')
      ),
      monacoBase: uriFromPath(
        path.join(__dirname, '../node_modules/monaco-editor/min/vs')
      )
    }
  });

export default () => <Editor width="100%" height="500px" language="javascript" value="const hello ='world';" />

@suren-atoyan
Copy link
Owner

Hey, I had eventually got through that and got it working :) so an example component that works for my specific setup was...

// webpack.config.js

import MonacoEditorWebpackPlugin from 'monaco-editor-webpack-plugin';

module.exports = {
    // ..... blah,
    plugins: [
        new MonacoEditorWebpackPlugin(),
    ]
}
// SomeComponent.js

import React from 'react';
import path from 'path';
import Editor, { monaco } from '@monaco-editor/react';

const 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(
        path.join(__dirname, '../node_modules/monaco-editor/min/vs/loader.js')
      ),
      monacoBase: uriFromPath(
        path.join(__dirname, '../node_modules/monaco-editor/min/vs')
      )
    }
  });

export default () => <Editor width="100%" height="500px" language="javascript" value="const hello ='world';" />

That's great, but please try without monaco-editor-webpack-plugin, I don't think you need it.

@ghost
Copy link
Author

ghost commented Mar 20, 2020

Can u plzz help me out aswell

@ghost
Copy link
Author

ghost commented Mar 20, 2020

I Tried the above method just now. Still Does Not Work !!!

@suren-atoyan
Copy link
Owner

suren-atoyan commented Mar 20, 2020

Can u plzz help me out aswell

Unfortunately, I am not able to do it. As I've already mentioned you have a special setup, and to be able to reproduce your case I have to have adobe photoshop installed on my machine (which is a paid software).

@ghost
Copy link
Author

ghost commented Mar 20, 2020

I am not using it for photoshop. I am using that template for making an after effects extension

@ghost
Copy link
Author

ghost commented Mar 21, 2020

I got it working yahoo!!!! . What i did was that i put the url like this :
'C:/Users//Desktop/<Project_filename>/node_modules/monaco-editor/min/vs/loader.js'
I got it to work without the webpack plugin

@ghost
Copy link
Author

ghost commented Mar 21, 2020

It does not show the loading thing now.
And By the way thanks for the providing the react component Suren Atoyan

@ghost ghost closed this as completed Mar 21, 2020
@xmsz
Copy link

xmsz commented Apr 17, 2023

@OwenMelbz you don't need steps 5 and 6. The problem is that the library tries to download sources from CDN, which in this setup isn't allowed. Please read this discussion to see how you can download monaco from node_modules or from other local places.

why electron can not use CDN mode

@Krishna-sm
Copy link

personally i am facing this problem on next js project check here

i solve this code with 1 configuration

where i find

visit docs

const MonacoEditor = dynamic(() => import('@monaco-editor/react'), { ssr: false });

// usage

  <MonacoEditor
   
  
                    theme='vs-dark'
                    options={{
                        wordWrap:'on',
                        wrappingStrategy:'advanced', 
                    }}
                    className=' w-full h-[50vh] lg:h-[63vh]' 
                    onChange={(e)=>SetFieldValue(selectFile,e as string)}
                    loading={<LoaderComponent/>}
                    language={selectFile.toLowerCase()} value={state[selectFile as keyof InitialiValuesProps]} />

now it's work fine

This issue was closed.
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

4 participants