title: Running Jest test get error "Cannot use import statement outside a module"
body: <p>In my node.js (with typescript) project, I try to use <a href="https://www.npmjs.com/package/crypto-random-string" rel="nofollow noreferrer">crypto-random-string</a> package for generating random string value.</p>
  <p>I use <a href="https://pnpm.io/" rel="nofollow noreferrer">pnpm</a> installed it:</p>
  <pre><code>pnpm i crypto-random-string
  </code></pre>
  <p>In my production code I use it as:</p>
  <pre><code>import cryptoRandomString from 'crypto-random-string';
  
  const cryptoStr = () =&gt; cryptoRandomString({ length: 10, type: 'ascii-printable' });
  
  </code></pre>
  <p>I have a jest code to unit test it, but when run jest, it complains:</p>
  <pre><code>my-project/node_modules/.pnpm/crypto-random-string@5.0.0/node_modules/crypto-random-string/index.js:3
      import {promisify} from 'node:util';
      ^^^^^^
  
      SyntaxError: Cannot use import statement outside a module
  
      &gt; 1 | import cryptoRandomString from 'crypto-random-string';
  </code></pre>
  <p>My <code>jest.config.ts</code>:</p>
  <pre><code>export default {
    jest: {
      preset: 'ts-jest',
      testEnvironment: 'node',
      transform: {
        'node_modules/variables/.+\\.(j|t)sx?$': 'ts-jest',
      },
      transformIgnorePatterns: ['node_modules/(?!variables/.*)'],
    },
  };
  </code></pre>
  <p>I tried the solutions from <a href="https://stackoverflow.com/questions/61781271/jest-wont-transform-the-module-syntaxerror-cannot-use-import-statement-outsi">here</a>, but not helpful for me.</p>
  <p>How to solve this issue?</p>