I've recently taken over a project that contains the following folder structure:
node_modules/
server/
├── node_modules/
├── src/
│ └── helpers/
│ ├── updateTransactions.ts
│ └── updateTransactions.test.ts
├── jest.config.ts
└── tsconfig.json
shared/
└── helpers/
└── datetime.ts
src/
└── index.tsx
jest.config.ts
tsconfig.json
When I navigate to the server
directory and run yarn test
, I encounter the error message:
Cannot find module '../../../shared/helpers/datetime.js' from 'src/helpers/updateTransactions.ts'
This issue seems to be due to Jest not recognizing how to handle the import statement, like
import { getFormattedDatetimeUtcFromBlockTimestamp } from '../../../shared/helpers/datetime.js';
within the updateTransactions.ts file.
It appears to be a simple configuration problem that needs addressing.
Despite attempting various solutions as documented in the commented-out code snippets here, such as:
- Jest + Typescript + Absolute paths (baseUrl) gives error: Cannot find module
- Jest gives `Cannot find module` when importing components with absolute paths
- Jest "Cannot find module" with typescript paths in CI
- Problem mapping path in ts-jest (TypeScript Jest), module cannot be found