Skip to content

Build issues: if viteConfig.root and viteConfig.build.outDir are absolute paths #3

@avasuro

Description

@avasuro

Issue Description

If viteConfig.root and viteConfig.build.outDir are defined as absolute paths in vite.config.ts, like so:

import path from 'path'
import { defineConfig } from 'vite'

const srcDir = path.resolve(__dirname, 'src')
const buildDir = path.resolve(__dirname, 'build')

export default defineConfig(({ mode }) => ({
  root: srcDir,
  build: {
    outDir: buildDir,
    // ...other config options
  },
}))

then running vite build results in different incorrect behaviors depending on the OS:

  • On Windows: The build fails with the error:

     ENOENT: no such file or directory, mkdir '{{PATH_TO_PROJECT}}\src\{{PATH_TO_PROJECT}}\build\monacoeditorwork'
    

    (Note: the {{PATH_TO_PROJECT}} is duplicated in the path)

  • On Linux/macOS: Monaco editor worker files are created somewhere deep inside the src folder

Cause

The issue likely originates from this line in the source code (line 148), which doesn't account for both root and outDir being absolute paths.

Temporary workaround

Specify a custom customDistPath in the plugin config:

monacoEditorPlugin({
  customDistPath: () => {
    let outDir = buildDir;
    // Special case: if CLI parameter `--outDir` is provided it takes precedence:
    if (process.argv.includes('--outDir')) {
      const index = process.argv.indexOf('--outDir')
      outDir = process.argv[index + 1]
    }
    return path.join(outDir, 'monacoeditorwork')
  },
}),

Links

UPD.: Just realized there's a similar bug report in the original repo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions