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

Unable to import TokenCredentialAuthenticationProvider with ESM #1377

Open
5 of 6 tasks
onionhammer opened this issue Jul 28, 2023 · 4 comments
Open
5 of 6 tasks

Unable to import TokenCredentialAuthenticationProvider with ESM #1377

onionhammer opened this issue Jul 28, 2023 · 4 comments
Assignees

Comments

@onionhammer
Copy link

onionhammer commented Jul 28, 2023

Bug Report

Unable to use TokenCredentialAuthenticationProvider with ESM

Prerequisites

  • Can you reproduce the problem?
  • Are you running the latest version?
  • Are you reporting to the correct repository?
  • Did you perform a cursory search?

For more information, see the CONTRIBUTING guide.

Description

Importing TokenCredentialAuthenticationProvider and running in node 18 fails.

Console Errors:

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import 'C:\Users\erikm\projects\graph-repro\node_modules\@microsoft\microsoft-graph-client\authProviders\azureTokenCredentials' is not supported resolving ES modules imported from C:\Users\erikm\projects\graph-repro\dist\index.js
Did you mean to import @microsoft/microsoft-graph-client/authProviders/azureTokenCredentials/index.js?
    at new NodeError (node:internal/errors:399:5)
    at finalizeResolution (node:internal/modules/esm/resolve:319:17)
    at moduleResolve (node:internal/modules/esm/resolve:945:10)
    at defaultResolve (node:internal/modules/esm/resolve:1153:11)
    at nextResolve (node:internal/modules/esm/loader:163:28)
    at ESMLoader.resolve (node:internal/modules/esm/loader:838:30)
    at ESMLoader.getModuleJob (node:internal/modules/esm/loader:424:18)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:77:40)
    at link (node:internal/modules/esm/module_job:76:36) {
  code: 'ERR_UNSUPPORTED_DIR_IMPORT',
  url: 'file:///C:/Users/erikm/projects/graph-repro/node_modules/@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials'
}

Screenshots: [If applicable, add screenshots to help explain your problem]

Steps to Reproduce

  1. Install @microsoft/microsoft-graph-client
  2. Set type: "module" in package.json
  3. Create an index.js file with JUST this:
 import { TokenCredentialAuthenticationProvider } from '@microsoft/microsoft-graph-client/authProviders/azureTokenCredentials';
  1. Run node index.js

Expected behavior:
The node application should run

Actual behavior:
Errors with

Error [ERR_UNSUPPORTED_DIR_IMPORT]: Directory import

SDK Version -3.0.5

  • Node (Check, if using Node version of SDK)

Node Version - v18.16.0

  • Browser (Check, if using Browser version of SDK)

Browser Name - [The name of Browser that you are using for SDK]

Version - [The version of the browser you are using]

@onionhammer onionhammer changed the title Unable to bundle TokenCredentialAuthenticationProvider with ESM Unable to importTokenCredentialAuthenticationProvider with ESM Jul 28, 2023
@onionhammer onionhammer changed the title Unable to importTokenCredentialAuthenticationProvider with ESM Unable to import TokenCredentialAuthenticationProvider with ESM Jul 28, 2023
@sebastienlevert
Copy link
Contributor

Thanks for reporting @onionhammer! I don't think we are doing a great job at ESM for the current version of the JS Graph client. We are currently building a v4 of the library based on https://aka.ms/kiota and its dependencies and we believe it'll be a lot better.

That being said, it's not a great experience currently and we'll see how big of a change this might be. @koros please have a look at reproducing.

@koros koros self-assigned this Aug 7, 2023
@sebastienlevert
Copy link
Contributor

Related to #1385

@marcosolina
Copy link

Hi guys, do we have any update on this issue? I have the same problem, I am using version 3.0.7 thanks

@marcosolina
Copy link

Hi all, just sharing a quick workaround that worked for me while waiting for further updates here

import { TokenCredentialAuthenticationProvider } from "@microsoft/microsoft-graph-client/lib/src/authentication/azureTokenCredentials/TokenCredentialAuthenticationProvider.js";

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

4 participants