导入多种模式时出错
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 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 !
最有用的评论
解决方案:
这在我添加
import "ace-builds/webpack-resolver"
后得到解决见https://github.com/securingsincity/react-ace/issues/725#issuecomment -543109155