#20370ERR_MODULE_NOT_FOUND when trying to run Vite inside a Docker container

Issue Details

about 2 months ago
No assignee
pending triage
pr0gramm3r101pr0gramm3r101
opened about 2 months ago
Author

Describe the bug

I'm migrating my website to Vite & React. My website uses Docker for containerization. But when i try to use Vite in my container (vite), this happens:

node:internal/modules/esm/resolve:274 throw new ERR_MODULE_NOT_FOUND( ^ Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/root/site/frontend/node_modules/rollup/parseAst' imported from /root/site/frontend/node_modules/vite/dist/node/chunks/dep-CXCa-anf.js at finalizeResolution (node:internal/modules/esm/resolve:274:11) at moduleResolve (node:internal/modules/esm/resolve:859:10) at defaultResolve (node:internal/modules/esm/resolve:983:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:801:12) at #cachedDefaultResolve (node:internal/modules/esm/loader:725:25) at ModuleLoader.resolve (node:internal/modules/esm/loader:708:38) at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:309:38) at #link (node:internal/modules/esm/module_job:202:49) { code: 'ERR_MODULE_NOT_FOUND', url: 'file:///root/site/frontend/node_modules/rollup/parseAst' } Node.js v24.3.0

Note that npm install was ran in the container, so the OS/arch mismatch cause is eliminated.

What i've tried

  • I double checked that rollup/parseAst exists at path /root/site/frontend/node_modules/rollup/dist/parseAst.js. Vite works perfectly out-of-the-box on my macOS host.

  • I saw this, but i can't change the extension because i have no control over the code of the libraries.

  • I tried using the npm flag --es-module-specifier-resolution=node as in this answer, but i couldn't pass it to npm because for some reason --node-arg and -n parameters got removed from npx.

Reproduction

see reproduction steps

Steps to reproduce

  1. npm create vite@latest
  2. Create the following Dockerfile:
FROM node:24 COPY . /root/site COPY vite.config.ts /root/site/vite.config.ts WORKDIR /root/site RUN npx tsc ENTRYPOINT exec npx \ vite \ --port 8002 \ --strictPort \ --open false
  1. Overwrite package.json:
{ "name": "toolbox-io-frontend", "version": "1.0.0", "private": true, "type": "module", "scripts": { "build": "npm run build:ts && npm run build:scss && npm run minify:html", "build:ts": "npm run compile:ts && npm run minify:ts", "compile:ts": "tsc", "minify:ts": "find . -name '*.js' -not -path './node_modules/*' -not -path './lib/*' -exec terser {} -o {} -m \\;", "build:scss": "sass css:css --no-source-map -s compressed && postcss css/*.css --use autoprefixer --no-map -d css", "minify:html": "find . -name '*.html' -not -path './node_modules/*' -exec html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true -o {} {} \\;", "clean": "find . -name '*.js' -not -path './node_modules/*' -not -path './lib/*' -delete && find css -name '*.css' -delete" }, "dependencies": { "[@highlightjs](https://github.com/highlightjs)/cdn-assets": "^11.11.1", "highlight.js": "^11.11.1", "marked": "^16.0.0", "react": "^19.1.0", "react-dom": "^19.1.0" }, "devDependencies": { "[@types](https://github.com/types)/jquery": "^3.5.32", "[@eslint](https://github.com/eslint)/js": "^9.29.0", "[@types](https://github.com/types)/react": "^19.1.8", "[@types](https://github.com/types)/react-dom": "^19.1.6", "[@vitejs](https://github.com/vitejs)/plugin-react": "^4.5.2", "eslint": "^9.29.0", "eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-react-refresh": "^0.4.20", "globals": "^16.2.0", "typescript": "~5.8.3", "typescript-eslint": "^8.34.1", "vite": "^7.0.0" } }
  1. npm install
  2. docker build -t site .
  3. docker run -it -p 8002:8002 site
  4. see the error

System Info

System: OS: macOS 26.0 CPU: (10) arm64 Apple M4 Memory: 116.91 MB / 16.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 20.19.3 - ~/.nvm/versions/node/v20.19.3/bin/node Yarn: 1.22.22 - /opt/homebrew/bin/yarn npm: 10.8.2 - ~/.nvm/versions/node/v20.19.3/bin/npm Browsers: Chrome: 138.0.7204.93 Safari: 26.0 npmPackages: [@vitejs](https://github.com/vitejs)/plugin-react: ^4.5.2 => 4.6.0 vite: ^7.0.0 => 7.0.2

Used Package Manager

npm

Logs

No response

Validations