Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Vite fails to handle tmp #413

Closed
5 of 6 tasks
innocenzi opened this issue Jan 3, 2022 · 2 comments
Closed
5 of 6 tasks

Vite fails to handle tmp #413

innocenzi opened this issue Jan 3, 2022 · 2 comments
Labels
duplicate This issue or pull request already exists upstream

Comments

@innocenzi
Copy link
Contributor

innocenzi commented Jan 3, 2022

Describe the bug

I was trying to test a file that uses tmp, and ran into the following issue:

- test/resolve.test.ts [ test/resolve.test.ts ]
TypeError: Object.defineProperty called on non-object
 ❯ ../../node_modules/.pnpm/tmp@0.2.1/node_modules/tmp/lib/tmp.js:763:8
 ❯ directRequest ../../../../../../../file:/D:/Code/projects/preset/preset/node_modules/.pnpm/vitest@0.0.112_vite@2.7.10/node_modules/vitest/dist/worker.js:9471:11
 ❯ async cachedRequest ../../../../../../../file:/D:/Code/projects/preset/preset/node_modules/.pnpm/vitest@0.0.112_vite@2.7.10/node_modules/vitest/dist/worker.js:9500:12
 ❯ async src/resolve.ts:5:31
      3| import tmp from 'tmp'
      4| import git from 'simple-git'
      5| import type { LocalDirectoryPreset, RepositoryPreset, ApplyOptions, LocalFilePreset } from './types'
       |                               ^
      6| import { debug } from './utils'
      7| 
 ❯ async directRequest ../../../../../../../file:/D:/Code/projects/preset/preset/node_modules/.pnpm/vitest@0.0.112_vite@2.7.10/node_modules/vitest/dist/worker.js:9471:5
 ❯ async cachedRequest ../../../../../../../file:/D:/Code/projects/preset/preset/node_modules/.pnpm/vitest@0.0.112_vite@2.7.10/node_modules/vitest/dist/worker.js:9500:12
 ❯ async test/resolve.test.ts:5:31

The issue is that tmp has the following snippet, which fails because module.exports is not what Vitest expects:

Object.defineProperty(module.exports, 'tmpdir', {
  enumerable: true,
  configurable: false,
  get: function () {
    return _getTmpDir();
  }
});

Multiple notes here:

  • I couldn't reproduce on StackBlitz (the test passes apparently)
  • The trace doesn't point to the right line of code
  • Locally, I am on a pnpm monorepository
  • When I run vitest with --no-threads, I don't even have an error, the file is completely ignored. If I use --threads, I get the error I pasted above. I have no idea why, at first I thought there was an issue with my filter.

I think that last point should be an issue on its own.

Reproduction

I couldn't reproduce on StackBlitz but if required I'll host my code on GitHub and link it.

System Info

System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
    Memory: 7.64 GB / 15.93 GB
  Binaries:
    Node: 16.13.1 - D:\Programmes\Laragon\bin\nodejs\node-v16.13.1\node.EXE
    Yarn: 1.22.17 - D:\Programmes\Laragon\bin\nodejs\node-v16.13.1\yarn.CMD
    npm: 8.1.2 - D:\Programmes\Laragon\bin\nodejs\node-v16.13.1\npm.CMD
  Browsers:
    Chrome: 96.0.4664.110
    Edge: Spartan (44.19041.1266.0), Chromium (96.0.1054.62)
    Internet Explorer: 11.0.19041.1202
  npmPackages:
    vite: ^2.7.10 => 2.7.10
    vitest: ^0.0.125 => 0.0.125

Used Package Manager

pnpm

Validations

@sheremet-va sheremet-va added the duplicate This issue or pull request already exists label Jan 3, 2022
@sheremet-va
Copy link
Member

sheremet-va commented Jan 3, 2022

Same as this: #393

You can try externalizing the dependency

deps: {
  external: [/tmp/], // or the path to tmp's index.js
},

We are waiting for the fix here: unjs/mlly#28

@sheremet-va
Copy link
Member

Fixed it https://github.com/vitest-dev/vitest/releases/tag/v0.0.139

No workaround is necessary.

chaii3 pushed a commit to chaii3/vitest that referenced this issue May 13, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jun 23, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
duplicate This issue or pull request already exists upstream
Projects
None yet
Development

No branches or pull requests

2 participants