Skip to content

Jsoneditor code mode requires worker-json.js from the absoute path not from the relative #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
smartameer opened this issue Feb 12, 2014 · 10 comments

Comments

@smartameer
Copy link

Hi,
I was using json-editor in "code" mode which is requiring worker-json.js
I have my scripts folder from where ace.min.js is loading, but it requires worker-json.js which is also in scripts directory, but dom error says that it's being requested from absolute url instead of scripts directory. May i know why this worker-json is required when https://github.com/josdejong/jsoneditor/blob/master/examples/03_switch_mode.html says no need of worker-json.js for code mode.

My Script block is

        var classContainer = document.getElementById('puppetClassEditor');
        var classOptions = { modes: ['code', 'tree'],
            search: false
        };
        $scope.classEditor = new jsoneditor.JSONEditor(classContainer, classOptions);
        $scope.classEditor.container.style.height = '150px';

        var paramContainer = document.getElementById('puppetParametersEditor');
        var paramOptions = { modes: ['code', 'tree'],
            search: false
        };
        $scope.paramEditor = new jsoneditor.JSONEditor(paramContainer, paramOptions);
        $scope.paramEditor.container.style.height = '150px';

I am using angularjs above this editor.

@smartameer
Copy link
Author

Sorry, My bad, I have renamed all the ace included libraries to .min.js which lead to error in showing worker json error.

tomalec added a commit to Juicy/juicy-jsoneditor that referenced this issue Jun 10, 2014
@tomalec
Copy link
Contributor

tomalec commented Jun 10, 2014

It seems that there is still an issue when loading from HTML Import.
With native support in Chrome Canary I get

2 Failed to load resource: the server responded with a status of 404 (Not Found)  http://juicy.github.io/juicy-jsoneditor/worker-json.js

Example here: http://juicy.github.io/juicy-jsoneditor/worker-json_bug.html

@josdejong
Copy link
Owner

That is an interesting one. This missing worker-json.js is a webworker loaded dynamically by Ace Editor. I suppose because relative paths are changed due to the import, ace editor tries to load the web worker from the wrong path.

@tomalec
Copy link
Contributor

tomalec commented Jun 11, 2014

Well according to W3C HTML Import spec, browser loads resources from location relative to importing document. So it works nice for all regular <link>,<script> tags, but I have no idea what is the magic beyond Ace fetching algorithm.

@josdejong
Copy link
Owner

but I have no idea what is the magic beyond Ace fetching algorithm.

There is no magic there, Ace uses require.js/AMD for (dynamic) module loading, though this particular issue is about running a Web Worker. This web worker is instantiated by Ace here. It creates a WorkerClient, which creates an HTML5 Web Worker from a relative url here. Polymer doesn't know about this relative url and so it isn't updated and breaks your application.

I'm not sure, but I can try whether the code for the web worker can be packaged together with the other modules, so there is no dynamic loading needed.

@andrewboni
Copy link

Anyone have any luck with this? Trying to solve #157 and this seems to be related. Thanks!

@josdejong
Copy link
Owner

@smartameer and @tomalec I've just refactored the JSONEditor to CommonJS modules and using brace (see #157 (comment)). This could resolve the problems when using the editor inside Polymer. Could you maybe give the version in the develop branch a try?

@semicoloncharmedlife
Copy link

I'm having essentially the same issue when doing a gulp build from bower packages. Since the build minifies all vendor code into a single vendor.js file the worker-json.js is included inline, but Ace still tries to load it as a file dynamically and 404s. Anyone have any ideas on how to get around this?

@sidthekidder
Copy link

Still getting this error, in angular 5.

@josdejong
Copy link
Owner

How can I reproduce the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants