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

Azure Identity node_modules issue: turing-apis/node_modules/@azure/identity/dist/index.js:1 Error: Cannot find module '@azure/msal-node' #29062

Closed
TedduNithin opened this issue Mar 26, 2024 · 8 comments
Assignees
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed The Azure SDK team member assisting with this issue believes it to be addressed and ready to close. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@TedduNithin
Copy link

Describe the bug
In our Node.js application, we are utilizing the Azure Identity and Azure KeyVault-Keys packages. However, upon running the server, I encounter the following issue within the Azure Identity package:

/Users/Nithin/Documents/Workspace/turing-gcp/turing-apis/node_modules/@azure/identity/dist/index.js:1
Error: Cannot find module '@azure/msal-node'
Require stack:
- /Users/Nithin/Documents/Workspace/turing-gcp/turing-apis/node_modules/@azure/identity/dist/index.js
- /Users/Nithin/Documents/Workspace/turing-gcp/turing-apis/azstore/index.js
- /Users/Nithin/Documents/Workspace/turing-gcp/turing-apis/handlers/transactions.js
- /Users/Nithin/Documents/Workspace/turing-gcp/turing-apis/server.js
- /Users/Nithin/Documents/Workspace/turing-gcp/turing-apis/index.js
    at Object.<anonymous> (/Users/Nithin/Documents/Workspace/turing-gcp/turing-apis/node_modules/@azure/identity/dist/index.js:5:18)
    at Generator.next (<anonymous>) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/Nithin/Documents/Workspace/turing-gcp/turing-apis/node_modules/@azure/identity/dist/index.js',
    '/Users/Nithin/Documents/Workspace/turing-gcp/turing-apis/azstore/index.js',
    '/Users/Nithin/Documents/Workspace/turing-gcp/turing-apis/handlers/transactions.js',
    '/Users/Nithin/Documents/Workspace/turing-gcp/turing-apis/server.js',
    '/Users/Nithin/Documents/Workspace/turing-gcp/turing-apis/index.js'
  ]
}

I've located the file responsible for the error within the node_modules directory. This file contains the following code at the beginning:

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var msalCommon = require('@azure/msal-node');
var logger$o = require('@azure/logger');
var abortController = require('@azure/abort-controller');
var coreUtil = require('@azure/core-util');
var coreClient = require('@azure/core-client');
var coreRestPipeline = require('@azure/core-rest-pipeline');
var coreTracing = require('@azure/core-tracing');
var fs = require('fs');
var os = require('os');
var path = require('path');
var promises = require('fs/promises');
var https = require('https');
var child_process = require('child_process');
var crypto = require('crypto');
var util = require('util');
var http = require('http');
var open = require('open');
var stoppable = require('stoppable');

It seems that the failure occurs in the initial "require" statement. When I manually switched the order of the "require" statements, placing the second one first, I encountered a different error related to the logger package.

I attempted to resolve the issue by installing the "@azure/msal-node" package using the command npm i @azure/msal-node. However, despite installing the missing module as indicated by the error message, the issue persists.

I have attempted to address this problem using Node.js versions 16, 18, and 20. Additionally, I have experimented with various stable versions of the "@azure/identity" package, yet the issue persists.

This problem has been impeding the progress of a production application for over a week now. I would greatly appreciate any assistance in resolving it. Thank you for your help.

Screenshots
Screenshot 2024-03-26 at 6 35 35 PM

@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Mar 26, 2024
@maorleger
Copy link
Member

Hey @TedduNithin - thanks for reaching out about this. By any chance are you using the esm package anywhere? You can find out by running npm ls esm in your directory. Could you share your package.json contents?

@maorleger maorleger self-assigned this Mar 26, 2024
@maorleger maorleger added the needs-author-feedback More information is needed from author to address the issue. label Mar 26, 2024
@github-actions github-actions bot removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Mar 26, 2024
Copy link

Hi @TedduNithin. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

@TedduNithin
Copy link
Author

TedduNithin commented Mar 26, 2024

Hi @maorleger,

Yeah I'm using esm in my project.

Here is my package.json contents

{
  "name": "turing-apis",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://gitlab.com/vishwamfrgo/vishwam-DKYC/web/turing/turing-apis.git"
  },
  "author": "Jagadish G <jagadish@vishwamcorp.com>",
  "license": "ISC",
  "homepage": "https://bitbucket.org/sukshi_tech/turing-apis#readme",
  "dependencies": {
    "@angular-devkit/schematics": "^15.2.6",
    "@azure/identity": "^3.4.2",
    "@azure/keyvault-keys": "^4.8.0",
    "@azure/msal-node": "^2.6.4",
    "ajv": "^6.12.6",
    "axios": "^0.23.0",
    "azure-storage": "^2.10.7",
    "base64-to-uint8array": "^1.0.0",
    "blob": "^0.1.0",
    "crypto": "^1.0.1",
    "crypto-js": "^4.1.1",
    "dotenv": "^16.0.3",
    "esm": "^3.2.25",
    "execution-time": "^1.4.1",
    "express": "^4.18.2",
    "express-fileupload": "^1.4.0",
    "form-data": "^4.0.0",
    "google-auth-library": "^8.7.0",
    "googleapis": "^118.0.0",
    "jose": "^4.14.1",
    "json-2-csv": "^4.0.0",
    "jsonwebtoken": "^9.0.0",
    "lodash": "^4.17.21",
    "moment": "^2.29.4",
    "morgan": "^1.10.0",
    "node-gyp": "^9.3.1",
    "pg": "^8.10.0",
    "querystring": "^0.2.1",
    "request-ip": "^3.3.0",
    "restify-errors": "^8.0.2"
  },
  "devDependencies": {
    "@types/node": "^20.11.30",
    "cookie-parser": "^1.4.6",
    "cors": "^2.8.5",
    "express-session": "^1.17.3"
  }
}

And here is the output of npm ls esm

turing-apis@1.0.0 /Users/Nithin/Documents/Workspace/turing-gcp/turing-apis
├─┬ blob@0.1.0
│ └── esm@3.2.25 deduped
└── esm@3.2.25
Screenshot 2024-03-26 at 7 22 13 PM

@github-actions github-actions bot added needs-team-attention This issue needs attention from Azure service team or SDK team and removed needs-author-feedback More information is needed from author to address the issue. labels Mar 26, 2024
@maorleger
Copy link
Member

maorleger commented Mar 26, 2024

Great! Thanks for the quick reply. Unfortunately this is an issue with @azure/msal-node , a dependency of @azure/identity and esm.

I was able to isolate it to @azure/msal-node a few weeks ago (minimal repro here)

Unfortunately the esm package which is now archived and not taking any changes, does not respect the exports field used in msal-node. There's an issue on esm but it has not gotten much traction.

A few things you could do:

  1. You might try one of the many forks of esm - for example https://www.npmjs.com/package/esm-wallaby which supposedly handles exports just fine
  2. You could create an issue on https://github.com/AzureAD/microsoft-authentication-library-for-js ; however, I do believe the bug is on the esm package side, since top level exports like those used in @azure/msal-node are perfectly valid

Hope this helps, sorry I don't have a better answer for you - it's an issue with esm

@TedduNithin
Copy link
Author

Thank you for your prompt response, @maorleger.

I will explore the ESM fork you suggested and update you accordingly. Additionally, I will close this issue here and open a new one in the repository you mentioned to seek further assistance.

Once again, thank you very much.

@maorleger
Copy link
Member

No problem! Hope this information helps 👍

@maorleger maorleger added the issue-addressed The Azure SDK team member assisting with this issue believes it to be addressed and ready to close. label Mar 26, 2024
@github-actions github-actions bot removed the needs-team-attention This issue needs attention from Azure service team or SDK team label Mar 26, 2024
Copy link

Hi @TedduNithin. Thank you for opening this issue and giving us the opportunity to assist. We believe that this has been addressed. If you feel that further discussion is needed, please add a comment with the text "/unresolve" to remove the "issue-addressed" label and continue the conversation.

@TedduNithin
Copy link
Author

Hi @maorleger,

Using the esm-wallaby package in place of esm package fixed the issue.

Thank you very much for your help; it's highly valued.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customer-reported Issues that are reported by GitHub users external to the Azure organization. issue-addressed The Azure SDK team member assisting with this issue believes it to be addressed and ready to close. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
None yet
Development

No branches or pull requests

2 participants