Skip to content

localizationLoader: SyntaxError 'Unexpected token export' — eval() cannot parse ESM powerbiGlobalizeLocales.js #114

Description

@chassagne

Bug

pbiviz start / pbiviz package (without --all-locales) fails to compile any visual that depends on powerbi-visuals-utils-formattingutils >= 7.x:

ERROR in ./node_modules/powerbi-visuals-utils-formattingutils/lib/globalize/powerbiGlobalizeLocales.js
Module build failed (from .../powerbi-visuals-webpack-plugin/src/localizationLoader.js):
SyntaxError: Unexpected token 'export'
    at Object.localizationLoader (.../src/localizationLoader.js:12:37)

Root cause

src/localizationLoader.js filters locales by running eval() on the source of powerbiGlobalizeLocales.js:

const result = Object.entries(eval(source)).filter(...)

In current powerbi-visuals-utils-formattingutils (7.0.0, pulled in by powerbi-visuals-utils-chartutils@9), that file is an ES module:

export const locales = {
    "ar": ["ar", "default", { ...

eval() cannot parse ESM syntax, so it throws SyntaxError: Unexpected token 'export'. The variableDeclaration slicing on the lines above (source.indexOf("locales = {")) also assumes the old non-ESM shape of the file.

The loader is only attached when --all-locales is not passed (WebPackWrap.js → configureLoaders, if (!includeAllLocales)), which is why the flag hides the bug.

Repro

  • powerbi-visuals-tools 7.2.1 (powerbi-visuals-webpack-plugin 5.0.3), Node 22.15.0, macOS
  • Visual with powerbi-visuals-utils-chartutils@^9.0.0 (→ formattingutils 7.0.0) imported from src
  • pbiviz start → webpack 5.110.2 compiled with 1 error (the SyntaxError above)
  • pbiviz start --all-locales → compiled successfully (loader skipped)

Workaround

Always pass --all-locales, at the cost of bundling every locale.

Suggested fix

Parse the file instead of eval'ing it — e.g. strip the export const prefix before evaluating (eval(source.replace(/^export\s+/, "") + ";locales")), or import the module properly. Locale filtering currently cannot work at all against ESM formattingutils.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions