unplugin-icons: Failed to read source code from /vercel/path0/_virtual_~icons/mdi/instagram.jsx

I get this when building on Vercel, and sometimes locally (using Nextjs). Redeploying usually fixes the issue

./_virtual_~icons/mdi/instagram.jsx
--
17:44:39.823 | Error: Failed to read source code from /vercel/path0/_virtual_~icons/mdi/instagram.jsx
17:44:39.824 |  
17:44:39.824 | Caused by:
17:44:39.824 | No such file or directory (os error 2)

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 6
  • Comments: 16

Most upvoted comments

Still an issue in 2024. Any solutions other than disabling Next.js build caching all together?

@antfu can you fix this problem? as i see this bug very old

Same here. Super annoying. Have to remove node_modules and reinstall every time this happens.

This can help temporarily resolve the issue.

import type { NextConfig } from 'next';
import Icons from 'unplugin-icons/webpack';

const nextConfig: NextConfig = {
  webpack: (config) => {
+   config.cache = false;
    config.plugins.push(
      Icons({
        scale: 1.5,
        compiler: 'jsx',
        jsx: 'react',
      })
    );
    return config;
  },
};

export default nextConfig;

Same issue, been experiencing for months now

I have exactly the same issue with NextJs. The solution is to delete .next folder and re-run the dev command. The problem is that it happens absolutely randomly – after the 5th or 10th re-launch of a project, which may make reproducing it an unobvious, but still doable, task. I have arranged a reproduction on Stackblitz – https://stackblitz.com/edit/stackblitz-starters-arrh29?file=pages%2Findex.js.

  1. After opening it, finish the process with ctrl+c.
  2. Run npm run dev command, and kill it again.
  3. Repeat until getting the following result:
SCR-20230613-kudw

It took me 5 attempts to finally get the error.

wait  - compiling / (client and server)...
error - ./_virtual_~icons%2Fri%2Faliens-fill.jsx
ENOENT: no such file or directory, open '/home/projects/stackblitz-starters-arrh29/_virtual_~icons%2Fri%2Faliens-fill.jsx'

Need to note that on my local project, I have tried it with auto-import and it didn’t fix the problem.

Recently switched from the Iconify API to unplugin-icons and first experienced this issue after merging features after unplugin-icons was setup which smells like a Next caching issue. I get the same kinds of errors in a Vercel build and locally:

Local build:

Error: ENOENT: no such file or directory, open '/{path-to-application}/_virtual_~icons%2Fmaterial-symbols%2Faccount-box-outline.jsx'

Vercel:

Error: ENOENT: no such file or directory, open '/vercel/path0/{application-name}/_virtual_~icons%2Fmaterial-symbols%2Faccount-box-outline.jsx'

Same solution as pointed out by others. Locally I deleted the .next directory. In Vercel I re-ran the build without the build cache.

Doing a bit of digging this may come from an incompatibility of the webpack-virtual-modules with Next’s caching (or possibly a bug in either). I am basing this exclusively on the _virtual_ part of the path which is defined by unplugin here. unplugin-icons consumes this, so presumably this issue isn’t relevant to this repo and should be opened further up the chain.

@antfu Could you please confirm?

I have the same issue from time to time with Nextjs locally. A fix for me is to delete the .next folder and then rerun yarn run dev.