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
Webflow Rippling Notion Flipkart ea OpenAI Microsoft bluesky Univision vercel bloomberg Brex

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.

Why am I getting `RULE` as `Default` and `REASON` as `Unrecognized` when deploying to an environment in Statsig?

When deploying to an environment in Statsig, if you encounter an issue where the RULE is always Default and the REASON is Unrecognized, it typically means that the SDK was initialized, but the config or feature gate you're trying to evaluate did not exist in the set of values. This could be due to a few reasons:

1. The feature gate or dynamic config you're trying to evaluate does not exist or is not correctly spelled in your code. Please double-check the spelling and case-sensitivity.

2. The SDK might not have been able to fetch the latest rules from the Statsig server. This could be due to a transient network issue. If so, restarting the client or server should fix it, or waiting for a server SDK to poll for updates (by default, every 10 seconds).

3. The Target App you added to the SDK key you are initializing with may not be set on the gate/config/experiment/layer you are checking in your application. If you are using target apps, be double check that the target application on the entity you are checking matches the target application on the SDK key.

4. The gate has no rules in it. Gates return false by default, so a gate with no rules always returns false. Checking a gate that does not exist also returns false. As an optimization, we've removed gates which do not exist from the payload to sdks. So you may see an "Unrecognized" check if the gate has no rules (and therefore returns false anyway)

If you're still having trouble, please provide more details about your setup and the issue, and ask in the Statsig Slack Community.

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!

Why the best build with 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