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

bug(vite): ENOENT: no such file or directory, open '/__skip_vite/.nuxt/components/nuxt-error.vue' #734

Closed
AndreyYolkin opened this issue Apr 4, 2023 · 6 comments · Fixed by #759
Labels
bug Something isn't working vite

Comments

@AndreyYolkin
Copy link
Contributor

Environment


  • Operating System: Linux (via Windows 11 WSL)
  • Node Version: v16.19.0 (also tested Node 18)
  • Nuxt Version: 2.16.3
  • Nitro Version: 2.3.2
  • Package Manager: [email protected]
  • Builder: vite
  • User Config: bridge, nitro, serverHandlers, devServerHandlers, devServer, typescript, buildModules
  • Runtime Modules: -
  • Build Modules: (), @nuxt/[email protected]

Reproduction

https://github.com/AndreyYolkin/nuxt-bridge-skip-vite
https://codesandbox.io/p/sandbox/frosty-leftpad-cn0sgz

Run npm run dev or open the Sandbox link
image

Describe the bug

In dev mode, Nuxt built-in files are not loading in a propper way, which causes ENOENT on server

Additional context

It remembers this issue: #649

"Literally no one cares, but I get annoyed by anything" - magic string to attract attention)

Logs

ERROR  1:13:33 PM [vite] Internal server error: ENOENT: no such file or directory, open '/__skip_vite/.nuxt/components/nuxt-error.vue'                                                13:13:33
      at Object.openSync (node:fs:590:3)
      at Object.readFileSync (node:fs:458:35)
      at getDescriptor (file:///home/user/nuxt-bridge-app-spa/node_modules/@vitejs/plugin-vue2/dist/index.mjs:86:66)
      at Context.load (file:///home/user/nuxt-bridge-app-spa/node_modules/@vitejs/plugin-vue2/dist/index.mjs:1075:28)
      at Object.load (file:///home/user/nuxt-bridge-app-spa/node_modules/vite/dist/node/chunks/dep-79892de8.js:43360:46)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async loadAndTransform (file:///home/user/nuxt-bridge-app-spa/node_modules/vite/dist/node/chunks/dep-79892de8.js:41038:24)


 ERROR  1:13:33 PM [vite] Internal server error: ENOENT: no such file or directory, open '/__skip_vite/.nuxt/components/nuxt-loading.vue'                                              13:13:33
      at Object.openSync (node:fs:590:3)
      at Object.readFileSync (node:fs:458:35)
      at getDescriptor (file:///home/user/nuxt-bridge-app-spa/node_modules/@vitejs/plugin-vue2/dist/index.mjs:86:66)
      at Context.load (file:///home/user/nuxt-bridge-app-spa/node_modules/@vitejs/plugin-vue2/dist/index.mjs:1075:28)
      at Object.load (file:///home/user/nuxt-bridge-app-spa/node_modules/vite/dist/node/chunks/dep-79892de8.js:43360:46)
      at runMicrotasks (<anonymous>)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async loadAndTransform (file:///home/user/nuxt-bridge-app-spa/node_modules/vite/dist/node/chunks/dep-79892de8.js:41038:24)
@danielroe
Copy link
Member

danielroe commented Apr 4, 2023

<attention attracted>

@mlbiche
Copy link

mlbiche commented Apr 4, 2023

Same issue here !

@BryceBarbara
Copy link

@danielroe Looks like this was broken in your PR #724, are there any plans to fix it?

@danielroe
Copy link
Member

For sure! Equally, you should feel free to submit a PR if you get to it before I do. 🙏

@AndreyYolkin
Copy link
Contributor Author

I didn't dive deeply but it's interesting for me, why it's working in Nuxt3. Also I'm curious about the origins of __skip_vite prefix 🫨

@BryceBarbara
Copy link

@danielroe I'm not familiar enough with the codebase however I did come up with a nasty workaround for the time being that others are free to use:

defineNuxtModule({
  meta: {
    name: 'SkipViteFix',
  },
  setup(_options, nuxt) {
    let cachedViteServer: ViteDevServer | null = null;
    nuxt.hook('vite:serverCreated', async (viteServer) => {
      cachedViteServer = viteServer;
    });
    nuxt.hook('server:devHandler', () => {
      const viteServer = cachedViteServer;
      if (!viteServer) {
        console.error('No vite dev server');
        return;
      }

      let insertionPoint = viteServer.middlewares.stack.findIndex(
        (m) =>
          m.handle instanceof Function &&
          m.handle.name === 'viteTransformMiddleware'
      );
      if (insertionPoint == -1) {
        console.error('Invalid middleware insertion point ' + insertionPoint);
        return;
      }
      viteServer.middlewares.stack.splice(insertionPoint, 0, {
        route: '',
        handle: (
          req: IncomingMessage & { _skip_transform?: boolean },
          _res: ServerResponse,
          next: (err?: any) => void
        ) => {
          // remove /__skip_vite/ from the URL
          if (req.url && req.url.includes('/__skip_vite/')) {
            const newUrl = req.url.replace('/__skip_vite/', '/');
            req.url = newUrl;
          }
          next();
        },
      });
    });
  },
})

@danielroe danielroe added bug Something isn't working vite and removed pending triage labels May 3, 2023
ianpurvis added a commit to ianpurvis/purvisresearch.com that referenced this issue May 5, 2023
ianpurvis added a commit to ianpurvis/purvisresearch.com that referenced this issue May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working vite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants