Can only have one anonymous define call per script file
Asked Answered
L

2

9

I'm creating monaco editor using loader.js but getting the error "Can only have one anonymous define call per script file" 2 times in console.

<script src="/monaco-editor/min/vs/loader.js"></script>

Code to create editor

require.config({ paths: { 'vs': '/monaco-editor/min/vs' }});
 require(['vs/editor/editor.main'], function() {                
    monacoEditor= monaco.editor.create(document.getElementById('coding-editor'), {
        value: [
        'function x() {',
        '\tconsole.log("Hello world!");',
        '}'
    ].join('\n'),
    language: 'javascript'
    });
 });

I tried to search the issue and found below related answer:

Some piece of code that you are loading is invoking define with an anonymous module id. You could:

load that code through the AMD loader (i.e. manually require it) such that the AMD loader creates the <script> tag.

load that code before the AMD loader (i.e. define will not be available to that piece of code)

unset define for the duration of evaluation of that script (i.e. if you load it with a <script> tag, then unset define before and restore it afterwards)

try to unset define.jquery, AFAIK jquery might be checking for that on the define function

This page has lot of jquery already and I understand this because of jQuery. Please help some to make me understood by example. Thanks

Laywoman answered 8/3, 2019 at 5:49 Comment(0)
G
2

I had the same issue this morning and I applied the second solution.

load that code before the AMD loader (i.e. define will not be available to that piece of code)

This works because define is being called from inside jQuery anonymously, as the error says. Explained further in the require.js website, which happens to use loader function (define, require) similar to loader.js.

In my case I simply made sure to include my loader after jQuery so the defines don't collide.

Glindaglinka answered 15/3, 2019 at 1:31 Comment(2)
Can you show an example of how you did that please?Dygall
@Dygall It's been a while since this, but after reading the context. The change is basically to load any other code using define before the loader is included so it doesn't interfere.Glindaglinka
Z
-1

I had tried to create script by tags, but got aler:'Can only have one anonymous define' So I just overwrite it :

        this.temp_define = window['define'];
        head.appendChild(loaders);
        window['define'] = undefined;
Zoroastrianism answered 7/2, 2021 at 5:49 Comment(1)
Explain your code, this does not make any sense, what's loaders and what are you doing exactly here?Bibliographer

© 2022 - 2024 — McMap. All rights reserved.