question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error: Cannot find module '@azure/logger' from '\node_modules\@azure\identity\dist'

See original GitHub issue

Current behavior:

Error: Cannot find module '@azure/logger' from ..\node_modules\@azure\identity\dist'

Desired behavior:

Under plugins/index.js this statement should work

const { DefaultAzureCredential } = require("@azure/identity")
const { SecretClient } = require("@azure/keyvault-secrets")

Test code to reproduce

  • create a sample cypress test add those 2 libraries
  • npm install @azure/keyvault-secrets
  • npm install @azure/identity

https://www.npmjs.com/package/@azure/keyvault-secrets

Versions

4.7.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
prma85commented, Jun 11, 2020

It did! This is what I’m trying to do:

const path = require("path")
const { SecretClient } = require("@azure/keyvault-secrets")
const { DefaultAzureCredential } = require("@azure/identity")

function getConfigurationByFile(file) {
  const pathToConfigFile = path.resolve("cypress", "config", `cypress.${file}.json`)

  return fs.readJsonSync(pathToConfigFile)
}

async function KeyVault(url, secretName) {
  const credential = new DefaultAzureCredential()
  const client = new SecretClient(url, credential)
  return await client.getSecret(secretName)
}

module.exports = (on, config) => {
  // accept a configFile value or use local by default
  const file = config.env.configFile || "local"
  var jsonFile = getConfigurationByFile(file)

  if(!process.env.CI){
    KeyVault("uri", "client_secret").then((secret) => {
      jsonFile.env.client_secret = secret.value
    })
    KeyVault("URI", "password").then((secret) => {
      jsonFile.env.password = secret.value
    })
  }

  console.log(jsonFile)

  return jsonFile
}

Did you have your problem solved? I am having the same issue when using typescript 🤔

But instead of plugin, I am using it as a command to get the token and do a login before each test.

It returns the error ‘@azure/logger

0reactions
rmnunescommented, Jul 2, 2020

@prma85 This is how I did, and it worked the way I want. under plugins -> index.js

const fs = require("fs-extra")
const path = require("path")
const { SecretClient } = require("@azure/keyvault-secrets")
const { DefaultAzureCredential } = require("@azure/identity")

function getConfigurationByFile(file) {
  const pathToConfigFile = path.resolve("cypress", "config", `cypress.${file}.json`)

  return fs.readJson(pathToConfigFile)
}

async function KeyVault(url, secretName) {
  const credential = new DefaultAzureCredential()
  const client = new SecretClient(url, credential)
  return await client.getSecret(secretName)
}

module.exports = (on, config) => {
  on("task", {
    getSecret({ url, secretName }) {
      return KeyVault(url, secretName)
    },
  })

  on("before:browser:launch", (browser = {}, launchOptions) => {
    if (browser.family === "chromium" && browser.name !== "electron") {
      launchOptions.args.push("--disable-dev-shm-usage")
    }

    return launchOptions
  })

  // accept a configFile value or use local by default
  const file = config.env.configFile || "local"
  return getConfigurationByFile(file)
}

later I created a command, under support, and called the task. You can’t use the keyVault function directly on your spec files. You need to use task for that.

Cypress.Commands.add("keyVault", (url) => {
  const keyVaultUri = Cypress.env("keyvault_uri")
  cy.task("getSecret", { url: keyVaultUri, secretName: "AADClientSecret" }).then((secret) => {
     // call your login passing secret.value
    .....
  })  
})

I hope that helps. xD

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Cannot find module '@azure/logger' from ... - GitHub
Using typescript, create the following azure.ts file. import { DefaultAzureCredential } from "@azure/identity" ...
Read more >
Azure/Node.js Unaught exception: Error: Cannot find module ...
There is no 'ms' package defined either in my project dependencies or in the node_modules folder, so I'm assuming this is a Microsoft/Azure...
Read more >
@azure/identity - npm
Provides credential implementations for Azure SDK libraries that can authenticate with Azure Active Directory. Latest version: 3.1.2, ...
Read more >
Azure Identity client library for JavaScript | Microsoft Learn
The Azure Identity library provides Azure Active Directory (Azure AD) token authentication through a set of convenient TokenCredential ...
Read more >
azure-identity - PyPI
The Azure Identity library focuses on OAuth authentication with Azure AD. It offers a variety of credential classes capable of acquiring an Azure...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found