Repository: deno
Issue: Using vitest in a monorepo produces an unexpected module dependency error
Labels: bug,node compat

Rewriting my issue from #23882 as requested, since it was bloated.

Trying to use Deno 2.1.4 with Vitest 2.1.8 in a monorepo produces a strange error.

The monorepo (nx) is roughly as follows:
- apps/
   -  node-app1/
   -  node-app2/
   -  deno-app/
       - functions/ 
       - deno.json, deno.lock...
       - node_modules
- libs/
   - shared/src/... 
- node_modules/
- package.json, package-lock.json

When i run `deno task --unstable-detect-cjs --unstable-sloppy-imports --unstable-node-globals test-vitest run` inside the deno-app folder, i get the following error:

```sh
 FAIL  functions/_tests/vitest.example.test.ts [ functions/_tests/vitest.example.test.ts ]
ReferenceError: exports is not defined
 ❯ ../../node_modules/redis/dist/index.js:16:23
     14|     for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
     15| };
     16| Object.defineProperty(exports, "__esModule", { value: true });
       |                       ^
     17| exports.createCluster = exports.createClient = void 0;
     18| const client_1 = require("@redis/client");
``` 

The error is related to node-redis package. I am not actually using node-redis as it is not compatible with Deno, though I have to keep it because my node apps use it. Also, the error indicates that Deno detects it from the node_modules outside the deno app, not the one inside the deno-app. The root node_modules is only for the node apps, and i don't reference anything there from deno-app.

**deno.json**
```json
{
  "importMap": "./functions/import_map.json",
  "nodeModulesDir": "auto",
  "compilerOptions": {
    "lib": ["deno.window", "deno.unstable"]
  },
  "tasks": {
    "test-vitest": "vitest"
  }
}
```

**import_map.json**:
```json
{
  "imports": {
    "assert": "node:assert",
    "async_hooks": "node:async_hooks",
    "buffer": "node:buffer",
    "child_process": "node:child_process",
    "crypto": "node:crypto",
    "deno-redis": "jsr:@db/redis@0.37.0",
    "dns": "node:dns",
    "dns/promises": "node:dns/promises",
    "@shared/": "../../../libs/shared/src/",
    "dotenv": "npm:dotenv",
    "events": "node:events",
    "fs": "node:fs",
    "fs/promises": "node:fs/promises",
    "happy-dom": "npm:happy-dom",
    "http": "node:http",
    "https": "node:https",
    "http2": "node:http2",
    "module": "node:module",
    "net": "node:net",
    "os": "node:os",
    "path": "node:path",
    "perf_hooks": "node:perf_hooks",
    "redis": "npm:redis",
    "querystring": "node:querystring",
    "readline": "node:readline",
    "readline/promises": "node:readline/promises",
    "stream": "node:stream",
    "stream/promises": "node:stream/promises",
    "stream/consumers": "node:stream/consumers",
    "stream/web": "node:stream/web",
    "tls": "node:tls",
    "tty": "node:tty",
    "url": "node:url",
    "util": "node:util",
    "vitest": "npm:vitest@2.1.8",
    "zlib": "node:zlib"
  }
}
```


**vite.config.mts**
```ts
import { defineConfig } from "vitest/config";
import path from "path";
export default defineConfig({
  root: Deno.cwd(),
  resolve: {
    alias: {
      "@shared": path.resolve("../../libs/shared/src"),
    }
  },
  test: {
    watch: false,
    globals: true,
    environment: "node", // also tried happy-dom
    include: ["functions/_tests/vitest.example.test.ts"],
    passWithNoTests: true,
    pool: "threads",
    isolate: false,
    setupFiles: [
      "./vitest.setup.mts"
    ]
  },
});
```