2

I'm using Monaco for JavaScript object literal creation, where I need just the basic type completion, plus a custom one (using monaco.languages.registerCompletionItemProvider('javascript', ...)).

Default JavaScript autocompletion

When I use the recommended solution in How to remove autocompletions for Monaco Editor using Javascript? :

monaco.languages.typescript.javascriptDefaults.setCompilerOptions(
  { noLib: true, allowNonTsExtensions: false}
)

...the result is much better:

Only custom autocompletion

... but now the developer console shows a continuous flow of uncaught errors when I interact with the Monaco Editor:

tsMode.js:8 
        
       Uncaught (in promise) Error: Could not find source file: 'inmemory://model/2'.
    at ln (tsWorker.js:250)
    at Object.sn [as getSyntacticDiagnostics] (tsWorker.js:250)
    at pm.getSyntacticDiagnostics (tsWorker.js:35306)
    at w.fmr (workerMain.js:17)
    at s._handleMessage (workerMain.js:13)
    at Object.handleMessage (workerMain.js:13)
    at m._handleRequestMessage (workerMain.js:13)
    at m._handleMessage (workerMain.js:13)
    at m.handleMessage (workerMain.js:13)
    at s.onmessage (workerMain.js:13)

How do I get rid of these errors?

Mike Lischke
  • 48,925
  • 16
  • 119
  • 181

1 Answers1

-1

I had the same problem and fixed by keeping the existing compiler options, and only overwriting the relevant properties. Like this:

const compilerOptions = monaco.languages.typescript.javascriptDefaults.getCompilerOptions();
  
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({
  ...compilerOptions,
  noLib: true,
});
ex0
  • 1