When attempting to run jest in my Typescript Next.js project, I encounter the following error:
Details:
node_modules/d3-scale/src/index.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){export {
^^^^^^
SyntaxError: Unexpected token 'export'
7 | import { useRouter } from 'next/router';
8 | import { gql } from '@apollo/client';
> 9 | import { scaleLinear } from 'd3-scale';
I have already attempted to include d3-scale in transformIgnorePatterns within my jest configuration.
const nextJest = require('next/jest');
const createJestConfig = nextJest({
dir: './',
});
const customJestConfig = {
moduleDirectories: ['node_modules', '<rootDir>/'],
testEnvironment: 'jest-environment-jsdom',
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
testPathIgnorePatterns: ['<rootDir>/.next/', '<rootDir>/node_modules/', '<rootDir>/pages/test.tsx'],
moduleNameMapper: {
'\\.(scss|sass|css)$': 'identity-obj-proxy',
},
transform: {
'\\.[jt]sx?$': 'babel-jest',
},
transformIgnorePatterns: [
'/node_modules/(?!d3-scale)',
],
};
module.exports = createJestConfig(customJestConfig);