Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.07k stars 1.19k forks source link

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 closed 6 months ago

TedduNithin commented 6 months ago

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
maorleger commented 6 months ago

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?

github-actions[bot] commented 6 months ago

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 commented 6 months ago

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
maorleger commented 6 months ago

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 commented 6 months ago

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 commented 6 months ago

No problem! Hope this information helps 👍

github-actions[bot] commented 6 months ago

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 commented 6 months ago

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.