Keep ES module syntax when bundling connectors for web - #465
Keep ES module syntax when bundling connectors for web#465MattiasBuelens wants to merge 1 commit into
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
Co-Authored-By: Mattias Buelens <mattias.buelens@dolby.com>
20069f0 to
f40b97c
Compare
|
Review: LGTM ✅ (approve)
|
| | Yospace SSAI | [](https://www.npmjs.com/package/%40theoplayer%2Freact-native-yospace) | [`Yospace`](https://github.com/THEOplayer/react-native-connectors/tree/main/yospace) | | ||
| | Youbora analytics | [](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 |
There was a problem hiding this comment.
@tvanlaerhoven Not sure if this is the best place to put this? We don't actually render this root README on the documentation website... 🤷
There was a problem hiding this comment.
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?
Summary
The e2e app's webpack config runs
babel-loaderwith@react-native/babel-presetover@theoplayer/**/*.js, which rewritesimport/exportinto CommonJS. The web connectors are published as"type": "module"packages, so webpack parses their prebuilt bundles as strict ESM, whereexports/require/moduledon't exist — the transpiled bundle then throwsUncaught ReferenceError: exports is not definedatObject.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: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 developmentinapps/e2e: compiles clean, noexports is not definedand no "module has no exports" warning (only the pre-existinguseTVEventHandlerwarnings fromreact-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