vite: Vue Vite Docker WSL2. Internal server error: EACCES: permission denied, stat '/root/.node_modules/plugin-vue:export-helper'

Describe the bug

Error running dev server in WSL2 Docker.

docker-compose:

  frontend:
    build: .
    command: npm run dev
    volumes:
      - ./:/frontend
    ports:
      - '8080:8080'

Dockerfile:

FROM node:lts-alpine
WORKDIR /frontend
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]

vite.config.js:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  server: {
    host: true,
    port: 8080
  }
})

screenshot4

Reproduction

https://github.com/sshiling/Vite-Vue-Docker-WSL2-Bug

System Info

System:
    OS: Linux 4.19 Ubuntu 20.04 LTS (Focal Fossa)        
    CPU: (1) x64 Intel(R) Core(TM) i5-9400F CPU @ 2.90GHz
    Memory: 129.67 MB / 979.44 MB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 6.14.15 - /usr/bin/npm

Used Package Manager

npm

Logs

frontend_1  |   vite v2.7.13 dev server running at:
frontend_1  |
frontend_1  |   > Local:    http://localhost:8080/
frontend_1  |   > Network:  http://172.19.0.2:8080/
frontend_1  |
frontend_1  |   ready in 259ms.
frontend_1  |
frontend_1  | 2:31:01 PM [vite] Internal server error: EACCES: permission denied, stat '/root/.node_modules/plugin-vue:export-helper'
frontend_1  |   Plugin: vite:import-analysis
frontend_1  |   File: /frontend/src/App.vue
frontend_1  |       at Object.statSync (node:fs:1536:3)
frontend_1  |       at isDirectory (/frontend/node_modules/resolve/lib/sync.js:31:23)
frontend_1  |       at loadNodeModulesSync (/frontend/node_modules/resolve/lib/sync.js:200:17)
frontend_1  |       at Function.resolveSync [as sync] (/frontend/node_modules/resolve/lib/sync.js:107:17)
frontend_1  |       at resolveFrom$3 (/frontend/node_modules/vite/dist/node/chunks/dep-f5552faa.js:3911:29)
frontend_1  |       at resolvePackageData (/frontend/node_modules/vite/dist/node/chunks/dep-f5552faa.js:30046:19)
frontend_1  |       at /frontend/node_modules/vite/dist/node/chunks/dep-f5552faa.js:30426:15
frontend_1  |       at Array.find (<anonymous>)
frontend_1  |       at tryNodeResolve (/frontend/node_modules/vite/dist/node/chunks/dep-f5552faa.js:30425:44)
frontend_1  |       at Context.resolveId (/frontend/node_modules/vite/dist/node/chunks/dep-f5552faa.js:30257:28)

Validations

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 10
  • Comments: 20 (3 by maintainers)

Most upvoted comments

Getting the same error on Ubuntu 20.04 in combination with docker

Downgrading to 2.6.14 works as a quick workaround but should not be the fix. @patak-dev do you have any solution?

Just tried yarn install and yarn dev and that works… maybe it’s an issue upstream with npm?

node@16 and vite@2.6.14 combo is works. 👍

vite@2.9.1 doesn’t works well in docker. It show permission denied error message in docker. 👎

Just tried yarn install and yarn dev and that works… maybe it’s an issue upstream with npm?

Using yarn seems resolve the problem.

For context: Docker: node:16.14-alpine npm: v8.3.1

I still get the error with both node-16 and node-16-alpine using version 2.6.14.

I found a workaround, if you mount your source directory in /root it works. This docker-compose.yml configuration works for me:

version: '3.2'
services:
  frontend:
    image: node:16-alpine
    working_dir: /root
    volumes:
      - ./frontend:/root
    command: npx vite --host

@playmean I saw that in the linked resolve PR, and it looks extremely rare. For the record, we merged https://github.com/vitejs/vite/pull/7612 because the change in resolve is causing real issues without any real bug report to justify it. I agree that the best would be to follow node, but I think we should do it once we get an issue with a setup that justifies this change. And adding these paths should be accompanied probably with other changes to avoid breaking other use cases, or properly document how to correct them, as the setup looks common enough.

I think this PR breaks native feature of Node that described here.

image

@patak-dev I have checked now, yes, PR fixes the issue. But I think first of all this is a problem with containerized environment, just for notice.