Skip to content
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

Uncaught (in promise) Error: Could not find source file: 'inmemory://model/node_modules #16

Open
dolanmiu opened this issue Jul 18, 2022 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@dolanmiu
Copy link

dolanmiu commented Jul 18, 2022

image

tsMode.js:8 Uncaught (in promise) Error: Could not find source file: 'inmemory://model/node_modules/react/package.json'.
    at Ve (tsWorker.js:254:8493)
    at Object.In [as getSyntacticDiagnostics] (tsWorker.js:254:13367)
    at Nm.getSyntacticDiagnostics (tsWorker.js:33954:2433)
    at y.fmr (workerMain.js:17:33335)
    at a._handleMessage (workerMain.js:13:97450)
    at Object.handleMessage (workerMain.js:13:97075)
    at C._handleRequestMessage (workerMain.js:13:93890)
    at C._handleMessage (workerMain.js:13:93344)
    at C.handleMessage (workerMain.js:13:93232)
    at a.onmessage (workerMain.js:13:97167)

I can see the models are there, but probably not attached to the editor or something?

image

image

@dolanmiu dolanmiu added the bug Something isn't working label Jul 18, 2022
@lukasbach
Copy link
Owner

lukasbach commented Jul 20, 2022

Hello @dolanmiu, thank you for your report. Can you share the code you put into monaco, and the code that you used to mount monaco and attach the auto-typings plugin?

@dolanmiu
Copy link
Author

Very simple, but I pass my own version of monaco

const model = monaco.editor.createModel('', 'typescript', monaco.Uri.parse('inmemory://model/widget.tsx'));
model.updateOptions({ tabSize: 2 });
this.editor = monaco.editor.create(this.editorContainer.nativeElement, {
  model,
  language: 'typescript',
  theme: 'vs-dark',
  automaticLayout: true,
});

monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
  ...monaco.languages.typescript.typescriptDefaults.getCompilerOptions(),
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  jsx: 'react' as any,
  lib: ['dom', 'esnext'],
});

 this.autoTypings = await AutoTypings.create(this.editor, {
      monaco,
      sourceCache: storage, // Cache loaded sources in localStorage. May be omitted
      onUpdate: (u, t) => {
        if (u.type === 'StoredToCache' || u.type === 'LoadedFromCache') {
          for (const origin of CONSUMER_SPA_ORIGINS) {
            this.window.postMessage([t], origin);
          }
        }
      },
      onError: (e) => {
        for (const origin of CONSUMER_SPA_ORIGINS) {
          this.window.postMessage([e], origin);
        }
      },
    });

@lukasbach
Copy link
Owner

Can you try to add the following to the compiler options:

moduleResolution: options.monaco.languages.typescript.ModuleResolutionKind.NodeJs,
allowSyntheticDefaultImports: true,
rootDir: options.fileRootPath,

and if you're not already doing that, maybe also try importing AutoTypings from monaco-editor-auto-typings/custom-editor rather from monaco-editor-auto-typings directly.

@adnanjpg
Copy link

Can you try to add the following to the compiler options:

moduleResolution: options.monaco.languages.typescript.ModuleResolutionKind.NodeJs,
allowSyntheticDefaultImports: true,
rootDir: options.fileRootPath,

and if you're not already doing that, maybe also try importing AutoTypings from monaco-editor-auto-typings/custom-editor rather from monaco-editor-auto-typings directly.

applying these steps fixed it for me, without specifying rootDir as I'm not sure where its value would come from.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants