Getting a Jest error of:
Jest encountered an unexpected token
with the details of:
SyntaxError: Cannot use ‘import.meta’ outside a module
on the code of:
export const srcDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '../', 'src')
but in my package.json config I have:
"jest": {
"verbose": true,
"testEnvironment": "node",
"roots": [
"__tests__",
"lib",
"src"
],
"modulePathIgnorePatterns": [
"<rootDir>/docs",
"<rootDir>/src",
],
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!chalk)",
"<rootDir>/node_modules/(?!import.meta)"
],
"transform": {
"\.[jt]sx?$": "babel-jest"
}
},
with:
"type": "module",
I’ve read the docs on:
- configuration
- code-transformation
and read through:
- Jest encountered an unexpected token
- Jest encountered an unexpected token when working with React TypeScript
- How to fix Jest encountered an unexpected token
- Jest tests are failing because of an unknown unexpected token “export”
- Jest encountered an unexpected token: React App with JS
What am I doing wrong and how can I get my jest test to pass?