IdentityModel / oidc-client-js

OpenID Connect (OIDC) and OAuth2 protocol support for browser-based JavaScript applications
Apache License 2.0
2.43k stars 842 forks source link

index.js exports differ from index.d.ts types #1308

Open x3ro opened 3 years ago

x3ro commented 3 years ago

In the process of trying to have a more debuggable build (given that, by default, the minified version is included - #753) I tried to instruct my webpack build to directly import index.js instead, like so:

configureWebpack: {
    resolve: {
      alias: {
        "oidc-client": path.resolve(
          __dirname,
          "node_modules/oidc-client/index.js"
        ),
      },
    },
  },

This works insofar as that it compiles, but it fails at runtime. The reason for this appears to be that index.js provides a default export of an object, whereas index.d.ts indicates that there should be a named export of the individual classes / interfaces. Or in code:

import { WebStorageStateStore } from 'oidc-client';

works according to the type definition, but in reality one would have to do:

import * as oidc from 'oidc-client';
oidc.WebStorageStateStore

To achieve the correct result, though this doesn't type check. This appears to be remedied by doing an export { ... } instead of an export default { ... } in index.js (at least that worked for my local build).

I'm not going to say this is a bug, because it does seem like I'm using the library in a different way than currently intended. That being said, I'm still curious as to why this discrepancy exists, and whether this is on your radar for v2.0.0.

PS: thanks for building and maintaining this library 🎉

brockallen commented 3 years ago

Yea, I know there are some oddities around this area, but this style of export was setup a long time ago and I've just never had a chance to rework it. That'd be a v2 since it's a breaking change.