React-ace: Error in console, doesnt effect the way component works. But its annoying.

Created on 11 Feb 2020  ·  3Comments  ·  Source: securingsincity/react-ace

Problem

Errors when importing multiple modes

a8a2cc68-d2aa-4415-8e0e-e9de7978ead3:1 Refused to execute script from 'http://localhost:3000/worker-css.js' because its MIME type ('text/html') is not executable.
(anonymous) @ a8a2cc68-d2aa-4415-8e0e-e9de7978ead3:1
a8a2cc68-d2aa-4415-8e0e-e9de7978ead3:1 Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'http://localhost:3000/worker-css.js' failed to load.
    at blob:http://localhost:3000/a8a2cc68-d2aa-4415-8e0e-e9de7978ead3:1:1

These errors dont mess anything up, everything works and it manages to change the mode successfully.
I am giving the user the ability to pick different modes(css, javascript, python, etc). So I am programatically importing the modes based on what the user asks for in a picker list.

Sample code to reproduce your issue

// This runs whenever a new mode is selected by the user
    const handleModeChange = (event) => {
      var currentMode = event.target.value;
      require(`ace-builds/src-noconflict/mode-${currentMode}`)
      setState({...state, currentMode})
    }


            <AceEditor
              mode={state.currentMode}
              width="100%"
              theme="twilight"
              value={state.code}
              onChange={onChange}
              name="code_editor"
              editorProps={{ $blockScrolling: true }}
            /> 

Most helpful comment

Solution:

This was resolved after I added import "ace-builds/webpack-resolver"
See https://github.com/securingsincity/react-ace/issues/725#issuecomment-543109155

All 3 comments

Getting the same error

import AceEditor from "react-ace"

import "ace-builds/src-noconflict/mode-javascript"
import "ace-builds/src-noconflict/theme-monokai"
//...
  <AceEditor
      name="Ace-editor"
      mode="javascript"
      fontSize={15}
      wrapEnabled={true}
      value={beautify(JSON.stringify(state.stepDetails))}
      theme="monokai"
      onChange={handleSchemaChange}
      enableBasicAutocompletion={true}
      enableLiveAutocompletion={true}
      editorProps={{ $blockScrolling: true }}
    />

Solution:

This was resolved after I added import "ace-builds/webpack-resolver"
See https://github.com/securingsincity/react-ace/issues/725#issuecomment-543109155

Thanks @pi0neerpat !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Yuanye picture Yuanye  ·  7Comments

tsmirnov picture tsmirnov  ·  4Comments

ponelat picture ponelat  ·  3Comments

SecMao picture SecMao  ·  4Comments

nenadlukic picture nenadlukic  ·  6Comments