-
-
Notifications
You must be signed in to change notification settings - Fork 8k
vite build ignores optimizeDeps.include #3898
Description
Describe the bug
optimizeDeps.include option in config file is ignored by vite build command, while dev-server (just vite command) performs optimizing steps for the included files.
I use these feature because of I have to deal with CommonJS modules. My project uses gRPC-Web and generetes JavaScript-clients by Protocol Buffer Compiler with gRPC-Web plugin. This tool can't generate ES modules syntax currently.
During migrating to Vite from Webpack I move the generated files to local package ("my-project-proto": "file:./my-project-proto") and instruct Vite to optimize it (convert from cjs -> esm) by optimizeDeps.include option.
npm run dev does the trick, and I can see properly converted files in the cache, but npm run build skip this step. Even when I intentionally make typo in value of optimizeDeps.include, then npm run build doesn't react to it, while npm run dev exits with error about the dependency: Error: Failed to resolve force included dependency: my-package-name-with-typo.
Reproduction
To investigate the problem, I experiment with it in specailly created minimal project: buggy state commit. To reproduce the bug, clone the repo and execute npm run build. This repo is not about gRPC-Web, but for illustrate more common pattern bug: using CommonJS modules in Vite project.
System Info
Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:
System:
OS: Linux 5.8 Ubuntu 20.10 (Groovy Gorilla)
CPU: (8) x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
Memory: 22.69 GB / 31.30 GB
Container: Yes
Shell: 5.8 - /usr/bin/zsh
Binaries:
Node: 12.18.2 - /usr/bin/node
npm: 6.14.8 - /usr/bin/npm
Browsers:
Chromium: 91.0.4472.114
Firefox: 89.0.1
npmPackages:
vite: ^2.3.7 => 2.3.8 Used package manager: npm