Jest encountered an unexpected token export transform and transformIgnorePatterns not working

Viewed 18

Jest is failing my tests with

Jest encountered an unexpected token
...
[...]\node_modules\[...]\src\index.js:9
    export { X };
    ^^^^^^

    SyntaxError: Unexpected token 'export'

I already tried adding "@babel/preset-react" and "jest" to my presets on babelrc(also tried renaming the file from babelrc to babel.config.js (and adjusting the "module.exports");

I already have both transformIgnorePatterns and moduleNameMapper on jest.config.js:

transform: {
    '^.+\\.(js|jsx|ts|tsx)$': '<rootDir>/node_modules/babel-jest'
},
transformIgnorePatterns: [
    '[/\\\\]node_modules[/\\\\](?!@ngrx|(?!deck.gl)|ng-dynamic)',
    '[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$',
    '^.+\\.module\\.(css|sass|scss)$',
    '<rootDir>/node_modules/[...]'
],
moduleNameMapper: {
    '^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
    '\\.(woff|eot|ttf|woff2|svg|css|scss|png|gif|mp3)$': '<rootDir>/__mocks__/fileMock.js',
    '[module_name]': '<rootDir>/node_modules/[...]/src/index.js',
},

I have no idea what else to do... the library have this package json (important info only):

  "main": "src/index.js",
  "module": "src/index.mjs",
  "types": "src/index.d.ts",

The imported lib on node_modules does not have a "dist". The exported info I need is an obj.

The library index.js is:

const X = {
  [OBJ_INFO]
}

module.exports = { X };

and the library is imported as:

import * as XY from '[lib_name]';

XY.X

I am using: "jest": "^28.1.1" "babel-jest": "^28.1.1", "babel-loader": "^8.2.4",

0 Answers
Related