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

Attempted import error: 'UserManager' is not exported from 'oidc-client-ts'. #133

Closed
pamapa opened this issue Nov 5, 2021 · 13 comments · Fixed by #139
Closed

Attempted import error: 'UserManager' is not exported from 'oidc-client-ts'. #133

pamapa opened this issue Nov 5, 2021 · 13 comments · Fixed by #139
Labels
bug Something isn't working

Comments

@pamapa
Copy link
Member

pamapa commented Nov 5, 2021

When using the react-oidc-context library v2.0.0.beta.1 in a project:

./node_modules/react-oidc-context/dist/react-oidc-context.mjs
Attempted import error: 'UserManager' is not exported from 'oidc-client-ts'.

@pamapa pamapa added the bug Something isn't working label Nov 5, 2021
@pamapa
Copy link
Member Author

pamapa commented Nov 5, 2021

when using "moduleResolution": "node"

oidc-client-ts.cjs

@qlerolland
Copy link

When using the react-oidc-context library in a project:

./node_modules/react-oidc-context/dist/react-oidc-context.mjs Attempted import error: 'UserManager' is not exported from 'oidc-client-ts'.

Have you installed oidc-client-ts ? (Which is a peerDependency)

@pamapa
Copy link
Member Author

pamapa commented Nov 5, 2021

Yes.

@pamapa
Copy link
Member Author

pamapa commented Nov 5, 2021

strange wise webpack (create react app) is mixing module(esm) and main(commonjs), why?

  • react-oidc-context (esm)
  • oidc-client-ts (commonjs)

@pamapa
Copy link
Member Author

pamapa commented Nov 9, 2021

The problem seems to be the the .mjs extension.
When i rename react-oidc-context.mjs to react-oidc-context.esm.js and adapt package.json accordingly it magically works.

https://webpack.js.org/guides/ecma-script-modules/

@kherock
I will change the esm name in this package + oidc-client-ts unless you have a better idea? This way webpack will autotetect the correct format...

@kherock
Copy link
Collaborator

kherock commented Nov 9, 2021

I can't reproduce this, and the .mjs extension is important for native ESM support from Node. I was actually going to suggest moving to the package exports field ahead of the 2.0 release.

What version of Node are you running, and what does your webpack config look like?

@pamapa pamapa reopened this Nov 9, 2021
@pamapa
Copy link
Member Author

pamapa commented Nov 9, 2021

We can change this back + make a fix. I was unable to find another solution yet.

We are using react create app (https://www.npmjs.com/package/react-scripts v4.0.3), which is using under the hood webpack v4.

Docu:
https://create-react-app.dev/docs/getting-started/

For Node.JS we are using v16.

@kherock
Copy link
Collaborator

kherock commented Nov 9, 2021

Ok, Webpack v4 is really the problem here. I think migrating to exports should solve this. I'm pretty sure Webpack 4 doesn't implement resolution for those and will just use the CJS bundle, can you let me know if a package.json like the following fixes it?

  "main": "dist/react-oidc-context.cjs",
  "types": "dist/react-oidc-context.d.ts"
  "exports": {
    ".": {
      "import": "./dist/react-oidc-context.mjs",
      "require": "./dist/react-oidc-context.cjs"
    },
    "./package.json": "./package.json"
  }
  // ...

@kherock
Copy link
Collaborator

kherock commented Nov 9, 2021

I think this is relevant:
reactioncommerce/reaction-component-library#399 (comment)

@pamapa
Copy link
Member Author

pamapa commented Nov 9, 2021

  "main": "dist/react-oidc-context.cjs",
  "module": "dist/react-oidc-context.mjs",
  "types": "dist/react-oidc-context.d.ts",
  "exports": {
    ".": {
      "import": "./dist/react-oidc-context.mjs",
      "require": "./dist/react-oidc-context.cjs"
    },
    "./package.json": "./package.json"
  }

still leads to this error:

./node_modules/react-oidc-context/dist/react-oidc-context.mjs
Attempted import error: 'UserManager' is not exported from 'oidc-client-ts'.

@pamapa
Copy link
Member Author

pamapa commented Nov 9, 2021

  "main": "dist/react-oidc-context.cjs",
  "types": "dist/react-oidc-context.d.ts",
  "exports": {
    ".": {
      "import": "./dist/react-oidc-context.mjs",
      "require": "./dist/react-oidc-context.cjs"
    },
    "./package.json": "./package.json"
  }

leads to:

./src/index.tsx
Attempted import error: 'AuthProvider' is not exported from 'react-oidc-context'.

@kherock
Copy link
Collaborator

kherock commented Nov 9, 2021

Ok, I'll see if I can find a happy medium for this issue soon. Dropping the .mjs might cause the least amount of friction, its only disadvantage is that it loses compatibility with Node's ESM loader and maybe webpack 5 under its default configuration.

@pamapa
Copy link
Member Author

pamapa commented Nov 10, 2021

I am wondering if it would make sense to wait for react-scripts v5, where they have switched to webpack v5. Within their milestone there is only one issue left. On the other hand we could go now with webapck v4 support and later drop that by using mjs extenstion...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants