Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Vitest 0.26.0 crashes with 'TypeError: Writable is not a constructor' #2533

Closed
6 tasks done
jeff-wishnie opened this issue Dec 19, 2022 · 4 comments · Fixed by #2538
Closed
6 tasks done

Vitest 0.26.0 crashes with 'TypeError: Writable is not a constructor' #2533

jeff-wishnie opened this issue Dec 19, 2022 · 4 comments · Fixed by #2538

Comments

@jeff-wishnie
Copy link

jeff-wishnie commented Dec 19, 2022

Describe the bug

After upgrading 0.25.8 -> 0.26.0 Vitest fails a simple unit test run with:
image

 ERROR  TypeError: Writable is not a constructor                                                                                                                                 09:07:36


 ERROR   ❯ setupConsoleLogSpy ../../.yarn/__virtual__/vitest-virtual-7105f2e077/0/cache/vitest-npm-0.26.0-ecce3965e0-5a603e57f6.zip/node_modules/vitest/dist/chunk-runtime-setup.4c1b529e.js:106:18


 ERROR      104|         timers.set(id, timer);                                                                                                                                  09:07:36
    105|       }
    106|       let buffer = stdoutBuffer.get(id);
       |                  ^
    107|       if (!buffer) {
    108|         buffer = [];


 ERROR   ❯ Module.setupGlobalEnv ../../.yarn/__virtual__/vitest-virtual-7105f2e077/0/cache/vitest-npm-0.26.0-ecce3965e0-5a603e57f6.zip/node_modules/vitest/dist/chunk-runtime-setup.4c1b529e.js:40:5


 ERROR   ❯ run ../../.yarn/__virtual__/vitest-virtual-7105f2e077/0/cache/vitest-npm-0.26.0-ecce3965e0-5a603e57f6.zip/node_modules/vitest/dist/entry.js:59:3                      09:07:36


 ERROR   ❯ ../../.yarn/cache/tinypool-npm-0.3.0-e11f8ec8eb-92291c309e.zip/node_modules/tinypool/dist/esm/worker.js:109:20                                                        09:07:36

Resolution: Reverted to 0.25.8

Reproduction

don't think a repro is needed, but can add if required

System Info

System:
    OS: macOS 13.0.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 308.41 MB / 32.00 GB
    Shell: 5.2.15 - /opt/homebrew/bin/bash
  Binaries:
    Node: 19.3.0 - /opt/homebrew/bin/node
    Yarn: 3.3.0 - /opt/homebrew/bin/yarn
    npm: 9.2.0 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 108.0.5359.124
    Edge: 108.0.1462.54
    Firefox: 107.0.1
    Safari: 16.1

Stack:
- Vite 4.0.2
- Vue 3.2.45
- TypeScript 4.9.3
- Yarn: 3.3.0 w/PnP

Used Package Manager

yarn

Validations

@alexlafroscia
Copy link

I'm getting a very similar error with an import of EventEmitter:

import { EventEmitter } from 'node:events';

let emitter: EventEmitter;

beforeEach(() => {
  emitter = new EventEmitter();
});

This worked perfectly fine with vitest@0.23.4 but now is failing with the following error on 0.26.0:

TypeError: EventEmitter is not a constructor
 ❯ tests/utils/events.test.ts:14:15
     12| 
     13| beforeEach(() => {
     14|     emitter = new EventEmitter();
       |               ^
     15| });
     16| 

If I use a debugger to explore what's imported, the module seems incorrect:

CleanShot 2022-12-19 at 12 48 59@2x

__vite_ssr_import_0__ is the import of node:events; it seems odd that it would only have the default and once exports when in reality, there are lot more things exported from node:events.

@alexlafroscia
Copy link

I wonder if this is related to #2512, which changed some handling around named imports... I wouldn't expect that to have affected imports from node:* modules, but maybe that was an unintended side-effect?

@sheremet-va
Copy link
Member

This is imported with await import(). Does importing this in native Node gives the same result? If yes, this is intended change.

@alexlafroscia
Copy link

This is imported with await import()

What are you indicating is imported this way?

Does importing this in native Node gives the same result? If yes, this is intended change.

No; the native behavior does not match what I'm seeing in Vitest. If I use the Repl to import node:events, I can access an EventEmitter named export without issue

Welcome to Node.js v16.15.0.
Type ".help" for more information.
> const { EventEmitter } = await import('node:events');
undefined
> EventEmitter
<ref *1> [Function: EventEmitter] {
  once: [AsyncFunction: once],
  on: [Function: on],
  getEventListeners: [Function: getEventListeners],
  EventEmitter: [Circular *1],
  usingDomains: true,
  captureRejectionSymbol: Symbol(nodejs.rejection),
  captureRejections: [Getter/Setter],
  EventEmitterAsyncResource: [Getter],
  errorMonitor: Symbol(events.errorMonitor),
  defaultMaxListeners: [Getter/Setter],
  setMaxListeners: [Function (anonymous)],
  init: [Function (anonymous)],
  listenerCount: [Function (anonymous)]
}

@github-actions github-actions bot locked and limited conversation to collaborators Jun 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants