Skip to content

Keep ES module syntax when bundling connectors for web - #465

Open
MattiasBuelens wants to merge 1 commit into
mainfrom
devin/1788101289-webpack-esm-babel
Open

Keep ES module syntax when bundling connectors for web#465
MattiasBuelens wants to merge 1 commit into
mainfrom
devin/1788101289-webpack-esm-babel

Conversation

@MattiasBuelens

Copy link
Copy Markdown
Contributor

Summary

The e2e app's webpack config runs babel-loader with @react-native/babel-preset over @theoplayer/**/*.js, which rewrites import/export into CommonJS. The web connectors are published as "type": "module" packages, so webpack parses their prebuilt bundles as strict ESM, where exports/require/module don't exist — the transpiled bundle then throws Uncaught ReferenceError: exports is not defined at Object.defineProperty(exports, "__esModule", …).

The existing workaround excluded the offending bundles by filename, which has to be extended for every new connector (and only worked because webpack previously resolved the UMD bundle, whose typeof exports === 'object' guards fail silently). Instead, tell the preset to leave module syntax alone:

-exclude: [/\.d\.ts$/, /cmcd-connector\.esm\.js$/, /conviva-connector\.esm\.js$/],
+exclude: [/\.d\.ts$/],
-presets: ['module:@react-native/babel-preset'],
+presets: [['module:@react-native/babel-preset', { disableImportExportTransform: true }]],

Customers with their own webpack config hit the same failure, so the root README documents the required option.

Verified with npx webpack --config ./web/webpack.config.js --mode development in apps/e2e: compiles clean, no exports is not defined and no "module has no exports" warning (only the pre-existing useTVEventHandler warnings from react-native-web).

No changeset: no published package changes.

Link to Devin session: https://dolby.devinenterprise.com/sessions/181afa65caf6457a820e64cc3d87ddb5
Open in Devin Desktop: https://dolby.devinenterprise.com/desktop/session/181afa65caf6457a820e64cc3d87ddb5?variant=devin
Requested by: @MattiasBuelens

@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@changeset-bot

changeset-bot Bot commented Aug 30, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f40b97c

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Co-Authored-By: Mattias Buelens <mattias.buelens@dolby.com>
@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1788101289-webpack-esm-babel branch from 20069f0 to f40b97c Compare September 1, 2026 11:14
@tvanlaerhoven
tvanlaerhoven requested review from tvanlaerhoven and removed request for tvanlaerhoven September 1, 2026 12:31
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Review: LGTM ✅ (approve)

  • Correct root-cause fix: disableImportExportTransform: true keeps ESM syntax so webpack handles the "type": "module" web-connector bundles itself, replacing the brittle per-connector filename excludes that would need extending for every new connector.
  • The README section is a good addition, since customers with their own webpack config hit the same exports is not defined error.
  • Scope is minimal (e2e webpack config + docs only, no published package changes), so no changeset is correctly needed. CI, including the web e2e suite, is green after the rebase on main.

Comment thread README.md
| Yospace SSAI | [![%40theoplayer/react-native-yospace](https://img.shields.io/npm/v/%40theoplayer%2Freact-native-yospace?label=%40theoplayer/react-native-yospace=)](https://www.npmjs.com/package/%40theoplayer%2Freact-native-yospace) | [`Yospace`](https://github.com/THEOplayer/react-native-connectors/tree/main/yospace) |
| Youbora analytics | [![%40theoplayer/react-native-analytics-youbora](https://img.shields.io/npm/v/%40theoplayer%2Freact-native-analytics-youbora?label=%40theoplayer/react-native-analytics-youbora=)](https://www.npmjs.com/package/%40theoplayer%2Freact-native-analytics-youbora) | [`Youbora`](https://github.com/THEOplayer/react-native-connectors/tree/main/youbora) |

## Bundling for web with webpack

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tvanlaerhoven Not sure if this is the best place to put this? We don't actually render this root README on the documentation website... 🤷

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it's not great here. The rendered surfaces are the per-package READMEs (typedoc's packages strategy picks them up for the API site, and npm shows them), so the alternative is a short "Web support" section in the READMEs of the connectors that pull in a web connector: conviva, nielsen and yospace. Downside is triplicating the same paragraph; upside is customers find it where they installed from.

Happy to do either — move it into those three READMEs, or drop it from this PR and document it on the documentation website instead. Which do you prefer?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant