markdown-preview.nvim: i m getting ```status failed```, some ```yarn.lock``` problem

done

○ markdown-preview.nvim   MarkdownPreview MarkdownPreviewStop MarkdownPreviewToggle   markdown
    You have local changes in `/home/daUnknownCoder/.local/share/nvim/lazy/markdown-preview.nvim`:
      * app/yarn.lock
    Please remove them to update.
    You can also press `x` to remove the plugin and then `I` to install it again.

Describe the bug A clear and concise description of what the bug is.

um lazy doesnt update the plugin and it says status failed 2023-10-15-200759_hyprshot

Expected behavior A clear and concise description of what you expected to happen. um it should update

Desktop (please complete the following information):

  • OS: linux

Config

  {
    "iamcco/markdown-preview.nvim",
    cmd = { "MarkdownPreview", "MarkdownPreviewStop", "MarkdownPreviewToggle" },
    init = function()
      vim.g.mkdp_filetypes = { "markdown" }
    end,
    ft = { "markdown" },
    config = function()
      local install_path = vim.fn.stdpath("data") .. "/lazy/markdown-preview.nvim/app"
      local node_modules = install_path .. "/node_modules"
      if vim.fn.empty(vim.fn.glob(node_modules)) > 0 then
        vim.cmd("!cd " .. install_path .. " && npm install")
      end
      vim.g.mkdp_auto_close = 0
    end,
  },

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Reactions: 4
  • Comments: 21

Commits related to this issue

Most upvoted comments

Check the commit above for an updated (temporary) fix for this. It’s asynchronous now so it won’t be blocking opening any markdown files and it also suppresses the big long output that comes from npm (which is benign anyway).

I’ve tested this on both Windows and Linux and it works as intended. Should be enough to keep the lazy.nvim warnings at bay until a permanent fix is in place.

Why not put npm install/yarn install and git restore part in the build property which is dedicated to the plugin post-installation or post-update. There seems no need to use a async job.

This worked well for me.

I had:

build = "cd app && npm install",

And changed it to:

build = "cd app && npm install && git restore .",

One uninstall & reinstall later, no more complaints.

Check the commit above for an updated (temporary) fix for this. It’s asynchronous now so it won’t be blocking opening any markdown files and it also suppresses the big long output that comes from npm (which is benign anyway).

I’ve tested this on both Windows and Linux and it works as intended. Should be enough to keep the lazy.nvim warnings at bay until a permanent fix is in place.

+1 for u

I’ve found a slightly hacky workaround that may work for others. I’m not a web dev, so the yarn’s and the npm’s really don’t mean a whole lot to me.

Looking at the error message and the git status of the plugin directory, I can see npm install is making changes to tracked files, so every time lazy.nvim does a fetch, it’s returning this message because there are local changes.

To fix this, I’ve added a git restore . to my install command, which resets the repo with the remote and stops lazy.nvim raising alarms when running updates. Here’s my current config:

return {
    "iamcco/markdown-preview.nvim",
    version = "0.0.10",
    cmd = { "MarkdownPreview", "MarkdownPreviewStop", "MarkdownPreviewToggle" },
    init = function()
        vim.g.mkdp_filetypes = { "markdown" }
    end,
    ft = { "markdown" },
    config = function()
        -- Can't get lazy build to work ¯\_(ツ)_/¯
        -- This first time loading the plugin, there will be a significant delay becuase the function is synchronous, but after that it shouldn't be noticeable
        -- TODO: Either figure out how to get lazy build to work, or figure out how to make this asynchronous
        local install_path = vim.fn.stdpath("data") .. "/lazy/markdown-preview.nvim/app"
        local node_modules = install_path .. "/node_modules"
        if vim.fn.empty(vim.fn.glob(node_modules)) > 0 then
            vim.cmd("!cd " .. install_path .. " && npm install && git restore .")
        end

        -- Options
        vim.g.mkdp_auto_close = 0
    end,
}

I’m getting something similar:

You have local changes in `$HOME/.local/share/nvim/lazy/markdown-preview.nvim`:
          * app/index.js
          * app/package.json
          * app/yarn.lock
Please remove them to update.
You can also press `x` to remove the plugin and then `I` to install it again.

I think it has something to do with the yarn version on your machine.

I tested using yarn v3.6.4 (latest stable) and v4.0.0-rc.53 (latest canary).

In both cases, running yarn install modifies the following files:

  • index.js
  • package.json
  • yarn.lock

These files are tracked by the git repo, so that’s probably what’s blocking the update.

I did test with yarn v1.22.19 (the latest 1.x version), and it did not change any tracked files.

Workarounds

  • Ensure you use v1.22.19 of yarn
  • Or, as @scottmckendry mentioned, you could just clean then reinstall.

Longer term - I have some ideas for the maintainers:

  • If you’re willing to, perhaps the app could be migrated to use a later version of yarn.
  • If not, maybe can add a note in the README, saying that users MUST use v1.x of yarn for it to work properly.

Thoughts?

This is nice! I think part of my problem was not using a function for the build. I’ve managed to simplify my config a lot based on your example, This is working on my Windows machine.

return {
    "iamcco/markdown-preview.nvim",
    ft = { "markdown" },
    cmd = { "MarkdownPreview", "MarkdownPreviewStop", "MarkdownPreviewToggle" },
    build = function()
        local install_path = vim.fn.stdpath("data") .. "/lazy/markdown-preview.nvim/app"
        vim.cmd("silent !cd " .. install_path .. " && npm install && git restore .")
    end,
    init = function()
        vim.g.mkdp_filetypes = { "markdown" }
        vim.g.mkdp_auto_close = 0
    end,
}

Thank you!

this still doesnt work for me, the plenary is quite stable [for now]

{
    "iamcco/markdown-preview.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim",
    },
    cmd = { "MarkdownPreview", "MarkdownPreviewStop", "MarkdownPreviewToggle" },
    init = function()
      vim.g.mkdp_filetypes = { "markdown" }
    end,
    ft = { "markdown" },
    config = function()
      local job = require("plenary.job")
      local install_path = vim.fn.stdpath("data") .. "/lazy/markdown-preview.nvim/app"
      local cmd = "bash"

      if vim.fn.has("win64") == 1 then
        cmd = "pwsh"
      end

      job
        :new({
          command = cmd,
          args = { "-c", "npm install && git restore ." },
          cwd = install_path,
          on_exit = function()
            print("Finished installing markdown-preview.nvim")
          end,
          on_stderr = function(_, data)
            print(data)
          end,
        })
        :start()

      -- Options
      vim.g.mkdp_auto_close = 0
    end,
  },

This still works, will check out the new one snip soon, anyway, u should update the Readme so new users won’t find this error

I did a test with the following on my Linux machine and found nothing wrong with node.js v18.18 and npm v9.8.1.

    build = function()
      --vim.fn["mkdp#util#install"]()
      -- Temp fix for the yarn.lock issue on update (assuming npm available on the system)
      local install_path = vim.fn.stdpath("data") .. "/lazy/markdown-preview.nvim/app"
      local node_modules = install_path .. "/node_modules"
      local cmd = not require("util").is_win() and "bash" or "pwsh"
      if vim.fn.empty(vim.fn.glob(node_modules)) > 0 then
        vim.cmd("!cd " .. install_path .. " && npm install")
      end
    end,

Why not put npm install/yarn install and git restore part in the build property which is dedicated to the plugin post-installation or post-update. There seems no need to use a async job.

ig @iamcco isnt available for now, and the issue seems to be resolved [for now] so i m closing this issue

@scottmckendry Creative solution!

I’m just curious, is there a reason for doing npm install instead of yarn install?

{
    "iamcco/markdown-preview.nvim",
    version = "0.0.10",
    cmd = { "MarkdownPreview", "MarkdownPreviewStop", "MarkdownPreviewToggle" },
    init = function()
        vim.g.mkdp_filetypes = { "markdown" }
    end,
    ft = { "markdown" },
    config = function()
        -- Can't get lazy build to work ¯\_(ツ)_/¯
        -- This first time loading the plugin, there will be a significant delay becuase the function is synchronous, but after that it shouldn't be noticeable
        -- TODO: Either figure out how to get lazy build to work, or figure out how to make this asynchronous
        local install_path = vim.fn.stdpath("data") .. "/lazy/markdown-preview.nvim/app"
        local node_modules = install_path .. "/node_modules"
        if vim.fn.empty(vim.fn.glob(node_modules)) > 0 then
            vim.cmd("!cd " .. install_path .. " && npm install && git restore .")
        end

        -- Options
        vim.g.mkdp_auto_close = 0
    end,
}

tried this got this thing:

:!cd /home/daUnknownCoder/.local/share/nvim/lazy/markdown-preview.nvim/app && npm install && git restore .
npm
 WARN deprecated circular-json@0.5.9: CircularJSON is in maintenance only, flatted is its successor.
npm
 WARN deprecated date-format@1.2.0: 1.x is no longer supported. Please upgrade to 4.x or higher.
npm
 WARN deprecated streamroller@0.7.0: 0.x is no longer supported. Please upgrade to 3.x or higher.
npm 
WARN deprecated log4js@3.0.6: 3.x is no longer supported. Please upgrade to 6.x or higher.
added 70 packages, and audited 71 packages in 10s
1 package is looking for funding
  run `npm fund` for details
7 vulnerabilities (1 moderate, 2 high, 4 critical)

To address issues that do not require attention, run:
  npm audit fix

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

i m doin this for now:

  {
    "iamcco/markdown-preview.nvim",
    version = "0.0.10",
    cmd = { "MarkdownPreview", "MarkdownPreviewStop", "MarkdownPreviewToggle" },
    init = function()
      vim.g.mkdp_filetypes = { "markdown" }
    end,
    ft = { "markdown" },
    keys = {
      { "<leader>mp", "<cmd>MarkdownPreview<CR>", desc = "MarkdownPreview" },
    },
    config = function()
      local install_path = vim.fn.stdpath("data") .. "/lazy/markdown-preview.nvim/app"
      local file_path = install_path .. "/yarn.lock"

      -- Check if the file exists
      local f = io.open(file_path, "r")
      if f ~= nil then
        io.close(f)
        -- Delete the file
        os.remove(file_path)
      end
      local node_modules = install_path .. "/node_modules"
      if vim.fn.empty(vim.fn.glob(node_modules)) > 0 then
        vim.cmd("!cd " .. install_path .. " && npm install && git restore .")
      end

      -- Options
      vim.g.mkdp_auto_close = 0
    end,
  },

ig @iamcco should check this out