okta-auth-js
okta-auth-js copied to clipboard
Can't compile with snowpack because this lib is mixing commonjs with esm
This library is mixing esm imports and commonjs require statements. This breaks compilation with snowpack.
Please see related discussion: https://github.com/snowpackjs/snowpack/discussions/1321
Thanks for submitting this issue. Internal ref: OKTA-402500
@ifeltsweet Thanks for reporting the issue! We'll look into solutions like dynamic import
and import * as ...
to see if we can replace the require statements in the SDK. Meanwhile, can you try the workarounds in the snowpack thread to unblock your progress?
None of the workarounds in that thread worked for us. Currently we are resorting to importing via script tag.
Any update on this one?
@dude0001 Can you provide more information about your use case? Like version numbers of relevant libraries and your snowpack config?
I am not familiar with snowpack myself, but I do not see a single require statement in our esm browser bundle
I do not think this issue is limited to Snowpack in scope. I did not think it would be appropriate to open another issue as fixing this issue would fix it for us as well. We have an Angular v16 app with WebAssembly dependencies we desire to be ESM only so it can be packed optimized for our use case. Using CommonJS mixed with ESM causes optimization bail outs and performance issues in the product.
@dude0001 This issue is over 2 years, a few major versions have been released since then that have improved our package exports. We do offer a pure ESM bundle. I suggest trying that and if you are still having issues file a new ticket with as much details are possible
@jaredperreault-okta I would love for this to be true and to give this a try. We are using Okta v7.4.0 of this package and getting these CommonJS errors. Can you point us to a code repo example of what you are referring to?
https://github.com/okta/okta-auth-js/blob/master/package.json#L22
getting these CommonJS errors
Did you forget to paste the errors?
Warning: /home/vsts/work/1/s/node_modules/@okta/okta-auth-js/esm/browser/core/AuthStateManager.js depends on 'p-cancelable'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /home/vsts/work/1/s/node_modules/@okta/okta-auth-js/esm/browser/idx/interact.js depends on 'cross-fetch'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /home/vsts/work/1/s/node_modules/@okta/okta-auth-js/esm/browser/idx/interact.js depends on 'tiny-emitter'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Warning: /home/vsts/work/1/s/node_modules/unload/dist/es/index.js depends on 'detect-node'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
Ah, these warnings come from a few dependencies (and sub-dependencies). A few modules in our dependency tree do not offer ESM exports. This does prevent ESM tree-shaking and other optimizations, however these modules are lightweight and shouldn't affect your bundle greatly