Error during deployment "Vite: not found"

I have a problem when deploying my site to netlify. I have a project with multiple svelte vite projects and one svelte project as a shared library. Its not a monorepo (which i am aware you have documentation for), because i couldnt get it to work locally (i needed separate node_modules folders for specific dependencies with different versions in each project, and a global node_modules for the shared dependencies, but it kept installing everything into global node_modules). Anyway, So now I have a setup like this:

  • shared/
    • src/
    • package.json
  • packages
    • webxr/
      • src/
      • package.json
    • aframe/
      • src/
      • package.json

I created an npm link so i can import from the shared project in the projects under packages. I tried using a “deploy.js” script where i run “npm install” in the shared folder and then “npm run build” in the corresponding packages project folder i want to deploy with the base directory being set to root level of the entire project. However, i get the following error in the “Building” section of my deploy log:

6:38:52 PM: Netlify Build
6:38:52 PM: ────────────────────────────────────────────────────────────────
6:38:52 PM: ​
6:38:52 PM: ❯ Version
6:38:52 PM: @netlify/build 29.31.1
6:38:52 PM: ​
6:38:52 PM: ❯ Flags
6:38:52 PM: baseRelDir: true
6:38:52 PM: buildId: 6592f89eed4f110008c050c9
6:38:52 PM: deployId: 6592f89eed4f110008c050cb
6:38:52 PM: packagePath: packages/webxr
6:38:52 PM: ​
6:38:52 PM: ❯ Current directory
6:38:52 PM: /opt/build/repo
6:38:52 PM: ​
6:38:52 PM: ❯ Config file
6:38:52 PM: No config file was defined: using default values.
6:38:52 PM: ​
6:38:52 PM: ❯ Context
6:38:52 PM: production
6:38:52 PM: ​
6:38:52 PM: Build command from Netlify app
6:38:52 PM: ────────────────────────────────────────────────────────────────
6:38:52 PM: ​
6:38:52 PM: $ node deploy.js
6:38:52 PM: Building projects… /opt/build/repo/shared /opt/build/repo/packages/webxr
6:38:54 PM: stdout:
6:38:54 PM: added 58 packages, and audited 59 packages in 1s
6:38:54 PM: 3 packages are looking for funding
6:38:54 PM: run npm fund for details
6:38:54 PM: found 0 vulnerabilities
6:38:54 PM: stderr:
6:38:54 PM: Error: Error: Command failed: npm run build
6:38:54 PM: sh: 1: vite: not found
6:38:54 PM: Failed to build: Error: Command failed: npm run build
6:38:54 PM: sh: 1: vite: not found
6:38:54 PM: at ChildProcess.exithandler (node:child_process:422:12)
6:38:54 PM: at ChildProcess.emit (node:events:517:28)
6:38:54 PM: at maybeClose (node:internal/child_process:1098:16)
6:38:54 PM: at ChildProcess._handle.onexit (node:internal/child_process:303:5) {
6:38:54 PM: code: 127,
6:38:54 PM: killed: false,
6:38:54 PM: signal: null,
6:38:54 PM: cmd: “npm run build”
6:38:54 PM: }
6:38:54 PM: ​
6:38:54 PM: (build.command completed in 1.5s)
6:38:54 PM: ​
6:38:55 PM: Finished processing build request in 15.22s

The content of the deploy.js script:

const { exec } = require('child_process');
const path = require('path');

// Function to run a command in a specified directory
function runCommand(command, directory) {
    return new Promise((resolve, reject) => {
        exec(command, { cwd: directory }, (error, stdout, stderr) => {
            if (error) {
                console.error(`Error: ${error}`);
                return reject(error);
            }
            console.log(`stdout: ${stdout}`);
            console.error(`stderr: ${stderr}`);
            resolve();
        });
    });
}

async function buildProjects() {
    try {
        // Directory two levels up
        const shared = path.join(__dirname, 'shared');
        const package = path.join(__dirname, 'packages/webxr');
        console.log("Building projects...", shared, package);
        // Run 'npm run build' in the parent directory
        await runCommand('npm install', shared);
        // Run 'npm run build' in the current directory
        await runCommand('npm run build', package);
    } catch (error) {
        console.error('Failed to build:', error);
    }
}

buildProjects();

The content of a package.json file in one of the packages project to show that “npm run build” maps to “vite build”:

{
  "name": "webxr",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview",
    "check": "svelte-check --tsconfig ./tsconfig.json"
  },
  "devDependencies": {
    "@sveltejs/vite-plugin-svelte": "^3.0.1",
    "@tsconfig/svelte": "^5.0.2",
    "svelte": "^4.2.8",
    "svelte-check": "^3.6.2",
    "tslib": "^2.6.2",
    "typescript": "^5.2.2",
    "vite": "^5.0.8"
  },
  "dependencies": {
    "three": "^0.160.0"
  }
}

How do i solve this? Or better yet, how can i make this deploy work? Im very tight on time right now and I simply couldnt get a monorepo setup to work locally, although that may be better for deployment.

Could you please tell us what site this is for? Linking to the build logs in our UI would be a good start.

But, here’s how to diagnose build failures and possibly repair them so you can try self-serving as we cannot promise any response time for forums posts:

Hey, thanks for your timely response! I’m sorry I wasn’t sure if I was linking the right stuff or not, but here is a link to the build log of the site deploy if you can access it:

Thank you for the info. I’ll take a look at it but like i said i’m very tight on time right now so any direct help is highly appreciated! :slight_smile:

Hi, @Alastorftw. You have vite in devDepenencies:

  "devDependencies": {
    "@sveltejs/vite-plugin-svelte": "^3.0.1",
    "@tsconfig/svelte": "^5.0.2",
    "svelte": "^4.2.8",
    "svelte-check": "^3.6.2",
    "tslib": "^2.6.2",
    "typescript": "^5.2.2",
    "vite": "^5.0.8"
  },

It won’t be installed in production environments for that reason as it is not a production dependency. If you move it (and likely several other dependencies) to dependencies (not devDependencies), that should resolve the issue.

Thank you for the reply Luke, unfortunately moving vite and several other dependencies into “dependencies” does not solve the issue, it still does not recognize vite during build process:

The content of a package.json file in one of the packages project

The package.json must be in the root and it should have the vite as a dependency. OR, simply cd into each directory and run npm install again.