-
Notifications
You must be signed in to change notification settings - Fork 12
Description
Description
I am using Mantine UI for my React SPA, and @deno/vite-plugin@1.0.4
fails to correctly resolve this dependency during vite dev
and vote build
with the following error:
deno task build
Task build vite build
vite v6.3.5 building for production...
✓ 6 modules transformed.
✗ Build failed in 384ms
error during build:
[vite]: Rollup failed to resolve import "@mantine/core" from "<Project Root>/src/main.tsx".
Minimally reproducible example
- Init a new deno project
- Add the following dependencies (refer to the
deno.json
file below for the exact versions):
deno add --npm react react-dom vite @deno/vite-plugin @mantine/core @vitejs/plugin-react
- Create a minimal
vite.config.ts
file in your project root:
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import deno from "@deno/vite-plugin";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [deno(), react()],
});
- Create a minimal
index.html
file in your project root:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
</head>
<body>
<div id="root"></div>
<script type="module" src="/main.tsx"></script>
</body>
</html>
- Create a minimal
main.tsx
file in your project root:
import React from "react";
import ReactDOM from "react-dom/client";
import { Title } from "@mantine/core";
ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<Title>Hello!</Title>
</React.StrictMode>
);
- Add a
vite build
andvite dev
task to yourdeno.json
file (full contents of deno.json copied below):
{
"tasks": {
"dev": "vite dev",
"build": "vite build"
},
"imports": {
"@deno/vite-plugin": "npm:@deno/vite-plugin@^1.0.4",
"@mantine/core": "npm:@mantine/core@^8.0.1",
"@std/assert": "jsr:@std/assert@1",
"@vitejs/plugin-react": "npm:@vitejs/plugin-react@^4.4.1",
"react": "npm:react@^19.1.0",
"react-dom": "npm:react-dom@^19.1.0",
"vite": "npm:vite@^6.3.5"
},
"compilerOptions": {
"lib": ["dom"]
}
}
- Try to run
deno task build
ordeno task dev
and they will both fail with this error.
(Very) probable cause
After some digging, I've discovered that this is due to the way @deno/vite-plugin
generates a dependency tree for all of the SPA's dependencies. In short, the deno info --json [file]
call made here is hitting the 1MB default stdout buffer length limit for packages with very large dependency trees.
I've added some debug logs my local cached version of this plugin to confirm:
// <User>/Library/Caches/deno/npm/registry.npmjs.org/@deno/vite-plugin/1.0.4/dist/resolver.js:24
const output = await new Promise((resolve, reject) => {
execFile(DENO_BINARY, ["info", "--json", id], { cwd }, (error, stdout) => {
+ id?.includes("@mantine/core") && console.log(stdout);
Re-running deno task dev
or deno task build
, you'll see that the output for the deno info --json [file]
call is truncated:
// ... truncated ~1MB of output
{
"specifier": "../../../core/MantineProvider/default-theme.mjs",
"code": {
"specifier": "file:///Users/<username>/Library/Caches/deno/npm/registry.npmjs.org/@mantine/core/8.0.1/esm/core/MantineProvider/default-theme.mjs",
"sp <--- output ends here
This is because execFile
has a default buffer of 1MB (see maxBuffer
option in the Node docs), and this command produces output larger than that for this particular package. Running this yourself you can see how many bytes this output produces:
> deno info --json "file:///Users/<username>/Library/Caches/deno/npm/registry.npmjs.org/@mantine/core/8.0.1/esm/index.mjs" | wc -c
7348447
This package's dependency tree must be huge, as this command returns ~7MB of output.
To quickly confirm this theory, I added maxBuffer: 1024 * 1024 * 10
to the option arg for the execFile
call and re-ran deno task build
and the error went away.