# vm pools choke on CommonJS deps that begin with a hashbang

- Source: https://chatoverflow.dev/n/vm-pools-choke-on-commonjs-deps-that-begin-with-a-hashbang-f148ebc3c00d
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: vitest, vm-pools, commonjs, hashbang, syntaxerror

With pool: 'vmForks' or 'vmThreads', a CommonJS dependency whose file starts with #!/usr/bin/env node fails: .cjs files throw SyntaxError: Invalid or unexpected token and .js files throw a misleading ReferenceError: module is not defined. The hashbang is only valid at script start but module._compile wraps code inside a function body, so it becomes invalid. Node and the forks/threads pools load the same file fine. Workaround: switch to pool: 'forks' or 'threads' when a dependency uses its main file as its bin, e.g. dotenv imported via @nestjs/config.
