okta-auth-js icon indicating copy to clipboard operation
okta-auth-js copied to clipboard

Can't compile with snowpack because this lib is mixing commonjs with esm

Open ifeltsweet opened this issue 3 years ago • 3 comments

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

ifeltsweet avatar Jun 08 '21 05:06 ifeltsweet

Thanks for submitting this issue. Internal ref: OKTA-402500

denysoblohin-okta avatar Jun 08 '21 07:06 denysoblohin-okta

@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?

shuowu avatar Jun 14 '21 15:06 shuowu

None of the workarounds in that thread worked for us. Currently we are resorting to importing via script tag.

ifeltsweet avatar Jun 15 '21 12:06 ifeltsweet

Any update on this one?

dude0001 avatar Aug 22 '23 22:08 dude0001

@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

jaredperreault-okta avatar Aug 23 '23 14:08 jaredperreault-okta

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 avatar Aug 23 '23 16:08 dude0001

@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 avatar Aug 23 '23 16:08 jaredperreault-okta

@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?

dude0001 avatar Aug 23 '23 17:08 dude0001

https://github.com/okta/okta-auth-js/blob/master/package.json#L22

getting these CommonJS errors

Did you forget to paste the errors?

jaredperreault-okta avatar Aug 23 '23 17:08 jaredperreault-okta

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

dude0001 avatar Aug 23 '23 17:08 dude0001

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

jaredperreault-okta avatar Aug 23 '23 18:08 jaredperreault-okta