microsoft / microsoft/powerbi-visuals-webpack-plugin

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

Open Beginner friendly
#114 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
40
Forks
33
PR merge metrics
No merged PRs in 30d

Description

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.jsconfigureLoaders, 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 startwebpack 5.110.2 compiled with 1 error (the SyntaxError above)
  • pbiviz start --all-localescompiled 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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/localizationLoader.js, then inspect WebPackWrap.js and configureLoaders to confirm when the loader runs. Reproduce with powerbi-visuals-utils-formattingutils 7.x using pbiviz start or package without --all-locales. Done means ESM locale files compile successfully with locale filtering, while the existing --all-locales path remains successful.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, webpack
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.