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

No matching export in "node-modules-polyfills:http" for import "createServer" #5602

Closed
harbar20 opened this issue Jan 23, 2023 · 10 comments · Fixed by #6349
Closed

No matching export in "node-modules-polyfills:http" for import "createServer" #5602

harbar20 opened this issue Jan 23, 2023 · 10 comments · Fixed by #6349
Assignees
Labels
answered Question has received "first qualified response" msal-node Related to msal-node package public-client Issues regarding PublicClientApplications question Customer is asking for a clarification, use case or information. tracked-internally Bugs that are tracked by Msft internally

Comments

@harbar20
Copy link

Core Library

MSAL Node (@azure/msal-node)

Core Library Version

1.14.6

Wrapper Library

Not Applicable

Wrapper Library Version

None

Public or Confidential Client?

Public

Description

I'm writing an app in Remix. I've imported @azure/msal-node and used it everywhere (you can find my code here).

However, when I build it, I get this error:
image

I've tried updating to the latest version of both the polyfills library and msal-node to no avail. Any ideas?

Error Message

image

Msal Logs

I'm not sure where to find this.

MSAL Configuration

{
    auth: {
        clientId: process.env.CLIENT_ID || "",
        authority: ""
    }
}

Relevant Code Snippets

https://github.com/harbar20/cal-client

Just clone the whole repo.

Reproduction Steps

  1. Clone my repo
  2. Run npm install
  3. Run npm run build

Expected Behavior

I expect it to not error, and actually work.

Identity Provider

Azure AD / MSA

Browsers Affected (Select all that apply)

Chrome, Firefox

Regression

No response

Source

External (Customer)

@harbar20 harbar20 added bug-unconfirmed A reported bug that needs to be investigated and confirmed question Customer is asking for a clarification, use case or information. labels Jan 23, 2023
@ghost ghost added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Jan 23, 2023
@github-actions github-actions bot added msal-node Related to msal-node package public-client Issues regarding PublicClientApplications labels Jan 23, 2023
@ghost ghost assigned sameerag Jan 23, 2023
@sameerag
Copy link
Member

@Robbie-Microsoft Can you check this please?

@ghost ghost added answered Question has received "first qualified response" Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Jan 23, 2023
@Klukies
Copy link

Klukies commented Jan 23, 2023

I have the same error with our Remix application. Since I'm using yarn, I've been patching out the createServer and calling the createServer with http.createServer instead.

Here's the path in case you're wondering what I'm doing:

diff --git a/dist/msal-node.esm.js b/dist/msal-node.esm.js
index 207414e38b20d9bbca33ad5f857c7eb204b41906..188be623b0bf16f7b30c6e51f187e64d084abcb9 100644
--- a/dist/msal-node.esm.js
+++ b/dist/msal-node.esm.js
@@ -1,6 +1,6 @@
 import { Constants as Constants$1, ProtocolMode, AzureCloudInstance, LogLevel, StringUtils, AccountEntity, CacheManager, IdTokenEntity, AccessTokenEntity, RefreshTokenEntity, AppMetadataEntity, ServerTelemetryEntity, AuthorityMetadataEntity, ThrottlingEntity, TokenCacheContext, AuthError, Logger, ResponseMode, AuthenticationScheme, AuthorizationCodeClient, RefreshTokenClient, SilentFlowClient, UsernamePasswordClient, ClientAuthError, OIDC_DEFAULT_SCOPES, ServerTelemetryManager, Authority, AuthorityFactory, UrlString, DeviceCodeClient, ServerError, CodeChallengeMethodValues, TimeUtils, ClientCredentialClient, OnBehalfOfClient } from '@azure/msal-common';
 export { AuthError, AuthErrorMessage, AzureCloudInstance, ClientAuthError, ClientAuthErrorMessage, ClientConfigurationError, ClientConfigurationErrorMessage, InteractionRequiredAuthError, InteractionRequiredAuthErrorMessage, LogLevel, Logger, PromptValue, ProtocolMode, ResponseMode, ServerError, TokenCacheContext } from '@azure/msal-common';
-import http, { createServer } from 'http';
+import http from 'http';
 import https from 'https';
 import { v4 } from 'uuid';
 import crypto from 'crypto';
@@ -1999,7 +1999,7 @@ class LoopbackClient {
       throw NodeAuthError.createLoopbackServerAlreadyExistsError();
     }
     const authCodeListener = new Promise((resolve, reject) => {
-      this.server = createServer(async (req, res) => {
+      this.server = http.createServer(async (req, res) => {
         const url = req.url;
         if (!url) {
           res.end(errorTemplate || "Error occurred loading redirectUrl");

@harbar20
Copy link
Author

@LukasCornille that worked, thanks! This should 100% be a fix implemented in an update to the library though.

@ghost ghost added Needs: Attention 👋 Awaiting response from the MSAL.js team and removed Needs: Author Feedback Awaiting response from issue author labels Jan 25, 2023
@sameerag
Copy link
Member

@harbar20 What are the conditions for this to fail? I would like a justification before we apply this fix. cc @bgavrilMS @Robbie-Microsoft

@ghost ghost added Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Jan 30, 2023
@bgavrilMS
Copy link
Member

@harbar20 @LukasCornille - can you please explain more about the polyfill and this fix, or where I can read up on this? Unlike the others on this thread, I am not a JS expert.

@bgavrilMS
Copy link
Member

Possible duplicate: #5598

@Klukies
Copy link

Klukies commented Jan 30, 2023

The patch I've created is a yarn patch. Meaning I'm changing the code from the package you (or the people working on this library) have published. The compiler Remix is using is ESBuild, all I'm doing in the patch is removing the named export { createServer } and calling it directly through the http default export which comes from node itself.

I'm not sure what caused this, but "just" doing what I've done, should fix the issue without any implications on the package itself.

Klukies added a commit to Klukies/microsoft-authentication-library-for-js that referenced this issue Jan 30, 2023
@harbar20
Copy link
Author

@sameerag Not sure of the precise conditions to fail, but it seems that if I try to run a server with msal-node, it fails due to this mistake in the library. @LukasCornille 's explanation above is more apt.

@ghost ghost added Needs: Attention 👋 Awaiting response from the MSAL.js team and removed Needs: Author Feedback Awaiting response from issue author labels Jan 30, 2023
@sameerag
Copy link
Member

Marking this as something to track. I will sync up with @bgavrilMS to confirm if this is something we want to support.

@ghost ghost added Needs: Author Feedback Awaiting response from issue author and removed Needs: Attention 👋 Awaiting response from the MSAL.js team labels Jan 31, 2023
@sameerag sameerag added Needs: Attention 👋 Awaiting response from the MSAL.js team tracked-internally Bugs that are tracked by Msft internally labels Jan 31, 2023
@ghost ghost removed the Needs: Author Feedback Awaiting response from issue author label Jan 31, 2023
@sameerag sameerag removed Needs: Attention 👋 Awaiting response from the MSAL.js team bug-unconfirmed A reported bug that needs to be investigated and confirmed labels Jan 31, 2023
@andrew-dias
Copy link

I had to update @Klukies' patch when updating to msal-node@2.0.1, since the file name has changed:

diff --git a/node_modules/@azure/msal-node/dist/network/LoopbackClient.mjs b/node_modules/@azure/msal-node/dist/network/LoopbackClient.mjs
index 825f58a..5aaab6e 100644
--- a/node_modules/@azure/msal-node/dist/network/LoopbackClient.mjs
+++ b/node_modules/@azure/msal-node/dist/network/LoopbackClient.mjs
@@ -1,7 +1,7 @@
 /*! @azure/msal-node v2.0.1 2023-08-11 */
 'use strict';
 import { Constants, UrlString } from '@azure/msal-common';
-import { createServer } from 'http';
+import http from 'http';
 import { NodeAuthError } from '../error/NodeAuthError.mjs';
 import { HttpStatus, LOOPBACK_SERVER_CONSTANTS, Constants as Constants$1 } from '../utils/Constants.mjs';
 
@@ -21,7 +21,7 @@ class LoopbackClient {
             throw NodeAuthError.createLoopbackServerAlreadyExistsError();
         }
         const authCodeListener = new Promise((resolve, reject) => {
-            this.server = createServer(async (req, res) => {
+            this.server = http.createServer(async (req, res) => {
                 const url = req.url;
                 if (!url) {
                     res.end(errorTemplate |

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered Question has received "first qualified response" msal-node Related to msal-node package public-client Issues regarding PublicClientApplications question Customer is asking for a clarification, use case or information. tracked-internally Bugs that are tracked by Msft internally
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants