Frequently Asked Questions

A curated summary of the top questions asked on our Slack community, often relating to implementation, functionality, and building better products generally.
Statsig FAQs
OpenAI Microsoft Notion Univision affirm Brex ea Ancestry Upwork Webflow Oura personio
GENERAL

How can I resolve Jest encountering unexpected token errors with the statsig-js module in my Angular application?

Date of slack thread: 4/12/24

Anonymous: Hi Statsig team,

After adding statsig-js: 4.52.0 in package.json for an Angular application, the unit tests started failing with:

    Jest encountered an unexpected token

    Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

    Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

    By default "node_modules" folder is ignored by transformers.

    Here's what you can do:
     • If you are trying to use ECMAScript Modules, see <https://jestjs.io/docs/ecmascript-modules> for how to enable it.
     • If you are trying to use TypeScript, see <https://jestjs.io/docs/getting-started#using-typescript>
     • 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/configuration>
    For information about custom transformations, see:
    <https://jestjs.io/docs/code-transformation>

    Details:

    /home/jferreira/git/omsurvey/aapps-ui-service/app/node_modules/statsig-js/node_modules/uuid/dist/esm-browser/index.js:1
    ({"Object.&lt;anonymous&gt;":function(module,exports,require,__dirname,__filename,jest){export { default as v1 } from './v1.js';
                                                                                      ^^^^^^

    SyntaxError: Unexpected token 'export'

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1796:14)
      at Object.require (node_modules/statsig-js/dist/ErrorBoundary.js:43:14)

Statbot: It appears that Jest is having trouble parsing the statsig-js module because it contains ECMAScript Modules (ESM) syntax, which Jest may not be configured to handle by default. Here are some steps you can take to resolve this issue:

  1. Transform ESM Modules: Ensure that your Jest configuration is set up to transform ESM modules. You may need to adjust the transformIgnorePatterns option to include the statsig-js package or use a custom transformer for ESM.
  2. Babel Configuration: If you’re using Babel, make sure that it is configured to transpile the ESM syntax. You might need to include the appropriate Babel plugins or presets that handle ESM.
  3. Mocking: If the module does not need to be transformed for your tests to run, you can mock the statsig-js module using Jest’s moduleNameMapper configuration option.
  4. Check Jest Documentation: Refer to the Jest documentation for more details on how to handle ECMAScript Modules, TypeScript, and custom transformations (https://jestjs.io/docs/configuration and https://jestjs.io/docs/code-transformation).

If you’ve tried these steps and are still encountering issues, it might be helpful to look into the specific Jest and Babel configurations for your project. Since the error is related to Jest’s handling of module syntax, the solution will involve configuring Jest and possibly Babel to properly handle the syntax used by the statsig-js package.

Join the #1 experimentation community

Connect with like-minded product leaders, data scientists, and engineers to share the latest in product experimentation.

Try Statsig Today

Get started for free. Add your whole team!

What builders love about us

OpenAI OpenAI
Brex Brex
Notion Notion
SoundCloud SoundCloud
Ancestry Ancestry
At OpenAI, we want to iterate as fast as possible. Statsig enables us to grow, scale, and learn efficiently. Integrating experimentation with product analytics and feature flagging has been crucial for quickly understanding and addressing our users' top priorities.
OpenAI
Dave Cummings
Engineering Manager, ChatGPT
Brex's mission is to help businesses move fast. Statsig is now helping our engineers move fast. It has been a game changer to automate the manual lift typical to running experiments and has helped product teams ship the right features to their users quickly.
Brex
Karandeep Anand
President
At Notion, we're continuously learning what our users value and want every team to run experiments to learn more. It’s also critical to maintain speed as a habit. Statsig's experimentation platform enables both this speed and learning for us.
Notion
Mengying Li
Data Science Manager
We evaluated Optimizely, LaunchDarkly, Split, and Eppo, but ultimately selected Statsig due to its comprehensive end-to-end integration. We wanted a complete solution rather than a partial one, including everything from the stats engine to data ingestion.
SoundCloud
Don Browning
SVP, Data & Platform Engineering
We only had so many analysts. Statsig provided the necessary tools to remove the bottleneck. I know that we are able to impact our key business metrics in a positive way with Statsig. We are definitely heading in the right direction with Statsig.
Ancestry
Partha Sarathi
Director of Engineering
We use cookies to ensure you get the best experience on our website.
Privacy Policy