Skip to content

import statements within vitest.workspace can't import .ts files using the .js extension #6519

@sxxov

Description

@sxxov

Describe the bug

thank you vitest team for this awesome project! i can't be happier leaving jest in the dust.

when using an import statment in vitest.workspace.ts, i can't import .ts files using the .js extension.
changing the extension to use .ts or removing the extension completely, makes the import succeed.

perculiarly, this seems to only fail if the import is inside the vitest.workspace.ts file, any further .js imports that exist within the imported modules will import successfully.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-t6tqec?file=vitest.workspace.ts

// vite.workspace.ts

import { foo } from './foo.js';
//       ^ Error: Failed to load url ./foo.js (resolved id: ./foo.js). Does the file exist?
//             at loadAndTransform (./node_modules/vite/dist/node/chunks/dep-DyBnyoVI.js:51857:17)
//             at async ViteNodeServer._transformRequest (./node_modules/vite-node/dist/server.mjs:524:16)
//             at async ViteNodeServer._fetchModule (./node_modules/vite-node/dist/server.mjs:486:17)
//             at async ViteNodeRunner.directRequest (./node_modules/vite-node/dist/client.mjs:277:46)
//             at async ViteNodeRunner.cachedRequest (./node_modules/vite-node/dist/client.mjs:206:14)
//             at async ViteNodeRunner.dependencyRequest (./node_modules/vite-node/dist/client.mjs:259:12)
//             at async C:\__Projects\Code\pawe\vitest.workspace.ts:4:31
//             at async ViteNodeRunner.runModule (./node_modules/vite-node/dist/client.mjs:399:5)
//             at async ViteNodeRunner.directRequest (./node_modules/vite-node/dist/client.mjs:381:5)
//             at async ViteNodeRunner.cachedRequest (./node_modules/vite-node/dist/client.mjs:206:14) {
//           code: 'ERR_LOAD_URL'

void foo;
// foo.ts

export foo = 'bar';

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 AMD Ryzen 9 4900HS with Radeon Graphics
    Memory: 4.02 GB / 15.42 GB
  Binaries:
    Node: 20.11.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.21 - C:\Program Files\nodejs\yarn.CMD
    npm: 10.8.1 - ~\AppData\Roaming\npm\npm.CMD
    pnpm: 8.7.4 - ~\AppData\Roaming\npm\pnpm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @vitejs/plugin-react: ^4.3.1 => 4.3.1
    @vitest/browser: ^2.1.1 => 2.1.1
    vite: ^5.4.6 => 5.4.6
    vitest: ^2.1.1 => 2.1.1

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions