question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Editor file loading gets hung, unable to display file content, due to loading config from CDN https://cdn.jsdelivr.net

See original GitHub issue

Describe the bug Editor loading gets hung, as a result fails to display the content of the file on the UI

Issue seems to be in Deploying and running from secure environment, due to loading monaco-editor config from a CDN

Exact Error is Refused to load the script 'https://cdn.jsdelivr.net/npm/monaco-editor@0.21.2/min/vs/loader.js' because it violates the following Content Security Policy

Below is the screenshot

image

To Reproduce Happens when u deploy the code in a prod like environment and URL is running as HTTPS

import React from "react";
import ReactDOM from "react-dom";
import Editor, { loader } from "@monaco-editor/react";
import { loader } from '@monaco-editor/react';
loader.config({ paths: { vs: 'path-to-your-node_modules/node_modules/monaco-editor/min/vs' } });

function App() {
  return (
   <Editor
     height="90vh"
     defaultLanguage="javascript"
     defaultValue="// some comment"
   />
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Expected behavior Editor should be able to load the file content There has to be more neater and easier way to load the config file

Screenshots Even though above is what is prescribed in another issue, it does not work and gives below syntax error in loading

image

Desktop (please complete the following information): I tried this on Mac, Chrome & Edge browser, but can confirm happening on all OS and browser

Additional context I had to solve using a very nasty workaround

  • npm install monaco-editor
  • Copied entire node_modules/monaco-editor to public folder
  • Copied entire node_modules/monaco-editor to src/ folder load the file by referring from “src” folder

Can we have a easier fix for this, as this way it is very difficult to Dockerise and Deploy, a lot of security related issues as we have to copy an external module to application’s source code

Please provide some pointers or direction too fix this clean way

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:10
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
zoonmancommented, Jul 13, 2021

It would make a lot of sense to load editor from an npm/yarn package without using any CDN. I’d prefer to let react-scripts to perform all necessary bundling etc.

2reactions
suren-atoyancommented, Nov 27, 2021

It would make a lot of sense to load editor from an npm/yarn package without using any CDN. I’d prefer to let react-scripts to perform all necessary bundling etc.

@rajiff @zoonman @vadimshvetsov @ColmanHumphrey we did this intentionally, to avoid using additional webpack plugins. react-scripts is not able to bundle monaco editor sources without an additional webpack plugin. Which means you have to eject or rewire your CRA application.

The whole idea of this library is to make monaco editor work without using any webpack plugins (which is required in applications generated by CRA). The workaround we’ve used here is not ideal, sure, it would be great to have consistency across the maintenance of packages, but unfortunately, this was the best workaround we could find to solve the problem.

I had to solve using a very nasty workaround

By using loader utility you can configure the library to load monaco sources from wherever you want. If you want to load it from your local files + you have only access to /public folder due to your setup/web-server configuration, it means that your mentioned “very nasty workaround” is the only way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't bundle Monaco Editor To disconnected environment
I'm getting 404 on the file: https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs/loader.js. Here is my configuration of ...
Read more >
Features - jsDelivr
Files are fetched directly from npm only the first time, or when S3 goes down. Load any project hosted on npm: https://cdn.jsdelivr.net/npm/package@version/ ...
Read more >
How To Secure Node.js Applications with a Content Security ...
When the browser loads a page, it executes a lot of code to render the content. The code could be from the same...
Read more >
Content and Experience (OCE) Attempt to ... - Oracle Support
Documents are not loading. Unable to Edit Sites. In Content and Experience Cloud, there are PDF and other files in a folder, when...
Read more >
Configuration fails to load due to missing file or directory - AskF5
You may also encounter this error when attempting to perform a ConfigSync. Supplemental Information. Related Content None.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found