Jest: Jest is Not Transpiling Local ES6 NPM Module Despite Proper Configuration

Created on 3 Oct 2018  ·  1Comment  ·  Source: facebook/jest

🐛 Bug Report

I have configured my project with all the needed Jest + Babel settings to transpile ES6 modules but when I attempt to run Jest, it does not transpile. I have followed all the set up steps outlined on this page: https://jestjs.io/docs/en/getting-started#using-babel and nothing works.

All my finer details can be found on this SO post.

https://stackoverflow.com/questions/52633286/jest-is-not-transpiling-es6-modules-in-test-syntaxerror-unexpected-token-expor

Expected behavior

I expect Jest to use babel-jest and transform my local ES6 module into a syntax it can understand.

Environment Info

System:
    OS: macOS High Sierra 10.13.6
    CPU: x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Node: 8.12.0 - ~/.nvm/versions/node/v8.12.0/bin/node
    npm: 6.4.1 - ~/.nvm/versions/node/v8.12.0/bin/npm
  npmPackages:
    jest: ^23.6.0 => 23.6.0

Output

Jest encountered an unexpected token

    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

    Here's what you can do:
     • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
     • If you need a custom transformation specify a "transform" option in your config.
     • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

    You'll find more details and examples of these config options in the docs:
    https://jestjs.io/docs/en/configuration.html

    Details:

    /Users/danchez/Developer/workspace/js/Test-Project/org-domain/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export * from './src/api';
                                                                                             ^^^^^^

    SyntaxError: Unexpected token export

>All comments

Hey @thedanchez, thanks for using Jest and sorry this is so frustrating

This is a help question not a bug so your StackOverflow question is the best place for this. If you can post a repo and ping me I'm happy to take a look

Was this page helpful?
0 / 5 - 0 ratings