React-ace: 控制台错误,不影响组件的工作方式。 但它很烦人。

创建于 2020-02-11  ·  3评论  ·  资料来源: securingsincity/react-ace

问题

导入多种模式时出错

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

这些错误不会搞砸任何事情,一切正常,并且成功地更改了模式。
我让用户能够选择不同的模式(css、javascript、python 等)。 所以我根据用户在选择器列表中的要求以编程方式导入模式。

重现您的问题的示例代码

// 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 }}
            /> 

最有用的评论

解决方案:

这在我添加import "ace-builds/webpack-resolver"后得到解决
https://github.com/securingsincity/react-ace/issues/725#issuecomment -543109155

所有3条评论

得到同样的错误

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 }}
    />

解决方案:

这在我添加import "ace-builds/webpack-resolver"后得到解决
https://github.com/securingsincity/react-ace/issues/725#issuecomment -543109155

谢谢@pi0neerpat

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

dmavrin picture dmavrin  ·  3评论

Bobcui001 picture Bobcui001  ·  5评论

levi0913 picture levi0913  ·  7评论

venil7 picture venil7  ·  3评论

anderoonies picture anderoonies  ·  5评论