ng2-ace-editor
ng2-ace-editor copied to clipboard
Changing mode causing unexpected errors
I'm trying to put the editor into JSON mode. With [mode]
set to json
on the editor I see this error:
Refused to execute script from 'http://localhost:4200/mode-json.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
So I added mode-json.js
to my angular-cli.json
as I've seen mentioned in other issues. My scripts array now looks like this:
"scripts": [
"../node_modules/ace-builds/src-min/ace.js",
"../node_modules/ace-builds/src-min/theme-tomorrow.js",
"../node_modules/ace-builds/src-min/mode-json.js"
],
The error in my browser console is now:
GET http://localhost:4200/worker-json.js 404 (Not Found)
I can't figure out what to make of this or what to do about it.
For what it's worth, I did try adding ../node_modules/ace-builds/src-min/worker-json.js
to my scripts array as well.
So, this feels hacky and stupid, but I managed to make the error go away and will put the "solution" here for anyone that might read it.
Basically, it's looking for worker-json.js
at the root so that's where I put it.
Do something like this:
cp node_modules/ace-builds/src-min/worker-json.js src
Then update .angular-cli.json to put "worker-json.js" into the assets
array.
The error is gone! No idea if the worker can function properly in that context but at least the error is gone!
Is there any better solution found for this?
I stopped looking. However, the worker does seem to function as I’m pretty sure that’s what does the syntax validation.
Just wanted to let you know, it's working for me in Angular 7 like this: "scripts": [ "node_modules/ace-builds/src-min/ace.js", "node_modules/ace-builds/src-min/mode-properties.js", ]
I did not have to change anything else.
"scripts": [ "node_modules/ace-builds/src-min/ace.js", "node_modules/ace-builds/src-min/mode-properties.js", ]
I could'nt make it work on latest version in angular 9. it always say
Refused to execute script from 'https://avanpost-ace-code-completion-m541f6.stackblitz.io/snippets/text.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. (index):1 Refused to execute script from 'https://avanpost-ace-code-completion-m541f6.stackblitz.io/mode-c_cpp.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.