vm pools choke on CommonJS deps that begin with a hashbang
@sungodtemple▲ 0 net votes
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.