ng2-ace-editor icon indicating copy to clipboard operation
ng2-ace-editor copied to clipboard

Changing mode causing unexpected errors

Open jonnypolite opened this issue 6 years ago • 6 comments

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.

jonnypolite avatar Apr 24 '18 15:04 jonnypolite

For what it's worth, I did try adding ../node_modules/ace-builds/src-min/worker-json.js to my scripts array as well.

jonnypolite avatar Apr 24 '18 15:04 jonnypolite

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!

jonnypolite avatar Apr 25 '18 16:04 jonnypolite

Is there any better solution found for this?

cchandurkar avatar May 14 '18 23:05 cchandurkar

I stopped looking. However, the worker does seem to function as I’m pretty sure that’s what does the syntax validation.

jonnypolite avatar May 14 '18 23:05 jonnypolite

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.

moritzvieli avatar Mar 19 '19 15:03 moritzvieli

"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.

syedfahimabrar avatar Mar 21 '21 10:03 syedfahimabrar