-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
Vite >=3.0.1 fails to resolve projects in monorepo #9202
Comments
Likely a regression from #9140. We're bundling the Vite config and all the related files, but because the relative imports point to a file from a package that could have it's own The original issue looks like a workaround for #5370, which doesn't work in the first place. Given this had worked in Vite 3.0.0, maybe it's worth finding a reasonable fix at the meantime, but the better solution overall is to compile the package as JS first. |
- temp workaround for vitejs/vite#9202
@bluwy thanks for your reply, I see that now! It doesn't make much sense for me to build it in this particular case as it's mostly various shared code being pulled in to For now, I ended up extracting fragments for vite build out of package with |
I've been thinking about this and it's quite tricky in general to support this. It's either:
And both aren't really good choices. The logic for bundling config files is also quite complex now since we had recent issues after Vite 3, and I'm hoping to not touch it anymore. We might have to intentionally break this in 3.0.1 (even though I hate to break semver), but given that it's a workaround before, and it's only 1 patch away. Maybe that's still acceptable. |
Same thing happens with
What if you don't have a compilation step? I'm using a shared package for defining config like so: https://stackblitz.com/edit/vitejs-vite-esn1xa?file=app%2Fvite.config.ts It worked with Edit: interestingly enough, when you remove |
We found a workaround that works for our project, it might work for others (ymmv): We figured out that we can run Vite through |
In a project w/ Click to expand{
errors: [
{
detail: undefined,
id: '',
location: {
column: 18,
file: '../node_modules/.bin/vite.js',
length: 9,
line: 2,
lineText: `basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")`,
namespace: '',
suggestion: ')'
},
notes: [],
pluginName: '',
text: 'Expected ")" but found "\\"$(echo \\""'
}
],
warnings: []
} |
Is there any workaround? I also need to import a common |
@Dreamacro a workaround is to move the common config out from a workspace package so it doesn't have it's own |
But actually its a breaking change. |
This issue makes really hard to use common Vite configs because usually common configs use npm packages. Hope the solution would be found. For now, here is my workaround: "scripts": {
"build": "vite build",
} After: "scripts": {
"build": "ts-node node_modules/vite/bin/vite.js build",
} |
still got Error: Cannot find module '@shared/xxxx' any other configs needed? |
@maketa521 I think no. One more thing - I use pnpm. Maybe this matters. Also, my node version is v16.16.0 |
related to vitejs/vite#9202
Describe the bug
Vite 3.0.1 and higher does not seem to resolve projects within the monorepo.
E.g. we got structure:
Since
[email protected].
, I'm getting the error below:This was working fine up till [email protected] and breaks in [email protected] and up.
Vite now fails on relative import in
vite.config.ts
Is there a more proper way to do this in vite?
Reproduction
https://stackblitz.com/edit/vitejs-vite-wg28sd?file=apps/app/vite.config.ts
cd apps/app npm install npm run build
System Info
Used Package Manager
pnpm (own project) / npm (stackblitz)
Logs
Validations
The text was updated successfully, but these errors were encountered: