I have organized a monorepo for a fullstack webapp with the directory structure outlined below:
.
├── client
│ ├── index.html
│ ├── package.json
│ ├── src
│ └── vite.config.ts
├── node_modules
├── package-lock.json
├── package.json
├── server
│ ├── package.json
│ └── src
├── tsconfig.json
└── tsconfig.node.json
When I execute npm run dev -ws client
, vite creates its own node_modules/
inside the client/
directory as shown below:
.
├── client
│ ├── index.html
│ ├── node_modules <--- this
│ │ └── .vite
│ │ └── deps_temp
│ │ └── package.json
│ ├── package.json
│ ├── src
│ └── vite.config.ts
The purpose of utilizing npm workspaces is to prevent multiple node_modules/
in every sub-project, and instead install all dependencies in the root node_modules/
. Vite creating its own node_modules/
seems counterintuitive to this objective.
I suspect there may be a misconfiguration (I initially set up vite using npx create-vite
).
Here's the output when running npm run dev -ws client
:
> @sargon-dashboard/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d3b0bfbab6bda793e3fde3fde3">[email protected]</a> dev
> vite client
(!) Could not auto-determine entry point from rollupOptions or html files and there are no explicit optimizeDeps.include patterns. Skipping dependency pre-bundling.
VITE v3.2.4 ready in 175 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
Below are the contents of vite.config.ts
:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()]
})
Contents of root/package.json
:
{
"name": "app",
"private": true,
"workspaces": [
"client",
"server"
]
}
Contents of root/client/package.json
:
{
"name": "@app/client",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
},
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@types/react": "^18.0.24",
"@types/react-dom": "^18.0.8",
"@vitejs/plugin-react": "^2.2.0",
"typescript": "^4.6.4",
"vite": "^3.2.3"
}
}
Contents of root/server/package.json
:
{
"name": "@app/server",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}