Skip to content

Import failure on file path with spaces #1937

@clarkdo

Description

@clarkdo

Describe the bug

Related issue: nitrojs/nitro#448

When importing a module path with spaces, vitest will throw Error: [vite-node] Failed to load, but it works fine in node env.

Reproduction

Let's define a simple test dir/util.mjs

export default 123

This file can be improved via Node.js:

const util = await import("file:///test/test%20dir/util.mjs")
console.log(util) // 123

But when we import this file in vitest, we'll see error:

import { describe } from 'vitest'

describe('test:suite', async () => {
  const util = await import("file:///test/test%20dir/util.mjs") // Error: [vite-node] Failed to load /test/test%20dir/util.mjs
  console.log(util)
})

System Info

System:
    OS: macOS 12.5.1
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.7.0
    npm: 8.15.0
  Browsers:
    Chrome: 104.0.5112.101
  npmPackages:
    vitest: ^0.22.1 => 0.22.1

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions