Skip to content

Module not found in monaco-run even using monacoRunAdditionalDeps #2392

@jesustorresdev

Description

@jesustorresdev

Describe the bug

As described in #2186, monacoRunAdditionalDeps is ignored so the import of packages fails in monaco-run.

Minimal reproduction

  1. Create a slide with monaco-run where some packages are impoted:
    ```ts {monaco-run}
    import { signal, effect } from '@angular/core';
    import { TestBed } from '@angular/core/testing';
    import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
    
    TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
    TestBed.runInInjectionContext(() => {
      const valueSignal = signal(1);
      console.log('Start');
      effect(() => {
        console.log('Signal:', valueSignal());
      });
    
      TestBed.flushEffects();
      console.log('After effect');
      valueSignal.set(1);
      TestBed.flushEffects(); 
      console.log('End');
    });
    
    
    
  2. Add monacoRunAdditionalDeps to frontmatter:
monacoRunAdditionalDeps:
 - '@angular/platform-browser-dynamic'
 - '@angular/core'
 - 'rxjs'
 - '@/snippets/angular-testbed'
  1. Install the dependencies in the project
  2. Start the dev server and see the error "Module not found"

Environment

  • Slidev version: 52.10.1

Possible fix

  1. monacoRunAdditionalDeps is completely ignored in the code. I think something like this is needed to add the dependencies in monacoRunAdditionalDeps.

    const deps = uniq(data.features.monaco.deps.concat(data.config.monacoTypesAdditionalPackages).concat(data.config.monacoRunAdditionalDeps))

    I tested it and it works.

  2. But that solution only allows using monacoRunAdditionalDeps in headmatter. The documentation talks about from matter. Maybe something like this could work:

    const perSlideDeps = data.slides.flatMap(slide => slide.frontmatter?.monacoRunAdditionalDeps || [])
    const deps = uniq(data.features.monaco.deps.concat(data.config.monacoTypesAdditionalPackages).concat(data.config.monacoRunAdditionalDeps).concat(perSlideDeps))

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions