Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error importing ESM bundle due to CJS logging dependency #473

Closed
jasonkarns opened this issue May 6, 2020 · 1 comment
Closed

Error importing ESM bundle due to CJS logging dependency #473

jasonkarns opened this issue May 6, 2020 · 1 comment

Comments

@jasonkarns
Copy link
Contributor

What I wanted to do

Trying to import the ESM bundle from optimizely-sdk

What I expected to happen

Expected it to import successfully.

What actually happened

When using rollup on a bundle that imports optimizely-sdk's ESM bundle:

[!] Error: 'ConsoleLogHandler' is not exported by ../optimizely-javascript-sdk/packages/optimizely-sdk/node_modules/@optimizely/js-sdk-logging/lib/index.js
https://rollupjs.org/guide/en/#error-name-is-not-exported-by-module
../optimizely-javascript-sdk/packages/optimizely-sdk/dist/optimizely.browser.es.min.js (1:7)

Steps to reproduce

The root cause is an issue with the commonjs wrapping of some of the optimizely deps. Because these are declared as external in the ESM bundle, this error does not manifest during optimizely's build. However, a trivial way to repro the issue:

  1. insert external: [] above:
  2. run npm run build

Doing this will force rollup to attempt to embed the logging dependency directly, rather than ignore it. This exposes the same problem that consumers will have when they attempt to import the main sdk ESM bundle (at which point, rollup will need to import the logging dep)

It appears that this was worked around for the UMD build by adding namedExports to the commonjs plugin. However, this option is no longer available with recent versions of the commonjs plugin. rollup/plugins#149

I believe this will be fixed implicitly by converting the logging dependency to ESM.

@optimizely/optimizely-sdk version:
4.0

@jasonkarns
Copy link
Contributor Author

This is probably a bit premature, since the commonjs plugin hasn't been released with the new syntheticNamedExports feature yet.

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

No branches or pull requests

1 participant