-1

I’m deploying to Deno Deploy, and I noticed that the generated build artifacts grows with each buld. it was ~101 MB, now it is 150 MB. my actual assets are less than 1 MB. I use Deno + Vite + React (and i need node_modules)

It is not node_modules folder problem. I removed it after build and still got artifacts 101 MB. I also tried to create new branch with bare minimum and my artifacts jumped from 101 MB to 150 MB.

How can I control artifacts in deno deploy?

Logs from deno deploy:

Executing build command
Task  deno task build && rm -rf node_modules
Task build deno run -A --node-modules-dir npm:vite build
vite v6.3.5 building for production...
Generated route tree in 81ms
transforming...
✓ 955 modules transformed.
rendering chunks...
computing gzip size...
ist/assets/index-DRFX6L5t.js            377.20 kB │ gzip: 117.28 kB
dist/assets/Editor-CoIp3zDK.js   1,236.99 kB │ gzip: 415.69 kB
(!) Some chunks are larger than 500 kB after minification. Consider:
- Using dynamic import() to code-split the application
- Use build.rollupOptions.output.manualChunks to improve chunking: https://rollupjs.org/configuration-options/#output-manualchunks
- Adjust chunk size limit for this warning via build.chunkSizeWarningLimit.
✓ built in 5.82s
Caching dependencies for the entrypoint
Preparing build artifact
[===============================================|            ] 15700/19393  80%
[===========================================================-] 19393/19393 100%
Uploading build artifact (101 MB)
Build finished

deno.json

{
  "nodeModulesDir": "auto",
  "tasks": {
    "install": "deno install",
    "dev": "deno run -A --node-modules-dir npm:vite",
    "build": "deno run -A --node-modules-dir npm:vite build",
    "analyze": "deno run -A --node-modules-dir npm:vite build --mode analyze",
    "preview": "deno run -A --node-modules-dir npm:vite preview",
    "serve": "deno run --allow-net --allow-read jsr:@std/http@1/file-server dist/",
    "start": "deno run --allow-net --allow-read --allow-env --env main.ts"
  },
  "compilerOptions": {
    "lib": ["ES2021", "DOM", "DOM.Iterable"],
    "jsx": "react-jsx",
    "jsxImportSource": "react",
    "jsxImportSourceTypes": "@types/react"
  },
}

vite.config.ts

import { defineConfig } from "vite";
import deno from "@deno/vite-plugin";
import react from "@vitejs/plugin-react-swc";
import { tanstackRouter } from "@tanstack/router-plugin/vite";

export default defineConfig({
  plugins: [
    deno(),
    tanstackRouter({
      target: "react",
      autoCodeSplitting: true,
    }),
    react(),
  ],
});

1 Answer 1

0

The issue was indeed with node_modules, but it turned out to be more complex than it first seemed.

Steps to fix

  1. Create a new app
    If Deno has accumulated artifacts, there doesn’t seem to be a documented way to clean them completely. Starting fresh with a new app is often the easiest path.

  2. When installing in deno deploy remove node_modules from root directory and remove Deno cache as well
    Run the following command:

    deno run --allow-write --allow-read cleanup.ts && deno clean
    

Example cleanup.ts script

try {
  await Deno.remove("./node_modules", { recursive: true });
  console.log("✅ node_modules cleaned up");
} catch (error) {
  if (error instanceof Deno.errors.NotFound) {
    console.log("ℹ️ node_modules already removed");
  } else {
    console.warn("⚠️ node_modules cleanup failed", error);
  }
}

Now my application deployed in 17.3s instead of 2 minutes

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.