Tips for making "npm run dev" function correctly following relocating the frontend of a React/Typescript project built with Vite to the 'client' directory

Currently, I am in the process of transitioning a frontend React/Typescript project created with Vite into a MERN stack project by incorporating a backend. To achieve this, I have relocated all frontend files to a "client folder" and established an empty "server" folder.

Prior to proceeding further, my intention is to ensure that the frontend functions correctly. However, when utilizing "npm run dev," which has been my standard practice until now, an error arises indicating the inability to locate a webpage on localhost:3000.

To address this issue, I made modifications to my "vite.config.ts" file as follows:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  root: './client',
  base: '/',
  plugins: [react()],
  server: {
    port: 3000
  }
})

Furthermore, here is the current state of my package.json within the client folder:

{
  "name": "vite-number-conversion",
  "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",
    "react-icons": "^4.7.1",
    "react-router-dom": "^6.8.1"
  },
  "devDependencies": {
    "@types/react": "^18.0.28",
    "@types/react-dom": "^18.0.11",
    "@vitejs/plugin-react": "^3.1.0",
    "autoprefixer": "^10.4.13",
    "postcss": "^8.4.21",
    "tailwindcss": "^3.2.7",
    "typescript": "^4.9.3",
    "vite": "^4.1.0"
  }
}

It seems probable that adjustments need to be made within the package.json file, yet I am uncertain about the correct course of action. I would greatly appreciate any guidance provided!

Answer №1

Ensure that the client directory contains the following files: vite.config.ts, index.html, package.json.

Delete the root and base properties from vite.config.ts:

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  server: {
    port: 3000
  }
})

Then run npm run dev.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to execute an executable file using Java on a Mac computer

Currently, my objective is to launch a server using bash, and I've already crafted an UNIX shell script for this purpose. However, I'm encountering difficulties in executing it through Java within Eclipse. Below is the code snippet that I attemp ...

In my attempt to install and require the packages "fs," "path," and "js-yaml" on my Windows 10 system, I encountered an issue. Specifically, only the "js-yaml" package resulted in the error message "

 Greetings! I am new to the world of computers and have been enjoying the insightful Q&As on this platform. This is my debut question on StackOverFlow, so please bear with me if my technical jargon or English seems a bit off.  I spent several hour ...

Cordova - Error: globalThis is not defined in the reference

I've been working through Cordova's Getting Started tutorial, but I hit a roadblock at the 2nd step. When I attempt to create my project using cordova create myApp, I encounter an error message that reads: C:\Users\foobar\AppData&b ...

Kindly include a @Pipe/@Directive/@Component annotation within an Angular 6 project

Encountering an issue in Angular6 where I am receiving the error message Please add a @Pipe/@Directive/@Component annotation Using angular CLI version: 6.1.4 angular version: 6.1.3 Node: 10.9.0 NPM: 6.2.0 After running ng serve in Terminal, the applicati ...

Error: The type definition file for webpack-env cannot be located during the build process

Our team is working on a .net core Asp.net framework Single Page Application (SPA). We recently encountered an issue while using the Nuget package manager console in Visual Studio 2017. Despite executing various commands, including npm init and npm install ...

Experiencing an npm error during the installation of npm on a Windows system

$ npm install -g addLocal Could not install c:\learn Windows_NT 6.1.7601 argv "c:\\Program Files\\nodejs\\node.exe" "c:\\Program Files\\nodejs\\node_modules\\npm\\bin&bsol ...

Encountering build:web failure within npm script due to TypeScript

Our project is utilizing the expo-cli as a local dependency in order to execute build:web from an npm script without requiring the global installation of expo-cli. However, when we run npm run build:web, we encounter the following exception. To isolate th ...

The npm encountered an error with code ENOENT and an error number of 34

Here is my initial script setup for a React project. "scripts": { "prestart": "babel-node tools/startMessage.js", "start": "npm-run-all --parallel test:watch open:src lint:watch", "open:src": "babel-node tools/srcServer.js", "lint": "node_ ...

leveraging multiple arguments in npm scripts

I have a command line script specified in the package.json file. "entity:create": "./node_modules/.bin/ts-node ./node_modules/.bin/typeorm entity:create", Now, I am trying to pass two flags into this script - -n and -d. The desired execution format is li ...

Tips on recycling JavaScript files for a node.js API

I'm currently using a collection of JS files for a node.js server-side API. Here are the files: CommonHandler.js Lib1.js Lib2.js Lib3.js Now, I want to reuse these JS files within an ASP.NET application. What's the best way to bundle these f ...

Set up Angular library by downloading from a specified local or network location

If I were to create an Angular library using the following commands: ng new libraries-workspace --create-application=false cd libraries-workspace ng generate library test-library After creating and building the library using the command below: ng build te ...

Optimal Strategy for organizing files in a node.js project

Exploring node more and considering "best practices" for handling npm specific files like node_modules. The project involves: REST API (node / express) Front-End (vue / Gatsby) Robots (automated tasks, js, cron jobs) App (Flutter), not set-up with node D ...

What is the proper way to set up Node modules in a subdirectory?

Is there a recommended approach for generating the node_modules folder in a subfolder? I am currently using Bower to install client-side files under a "client" folder and would like to do the same with NPM for server-side dependencies. For instance: MyApp ...

Require assistance in establishing a secure localhost using Node.js (NPM)

After exploring numerous methods, I have yet to successfully enable HTTPS for my Aurelia application (running via npm start) on Windows 10. If you have a foolproof solution for achieving this, please share it with me. Your help would be greatly welcomed. ...

Create a variety of web pages with the powerful Quasar framework

Currently, I am facing a challenge in creating a multi-page website with Quasar to be deployed on Netlify. It seems that Quasar is only generating the index.html file. I have attempted to use both Quasar build and Quasar build --mode ssr, but unfortunatel ...

Issues encountered when attempting to lower the version of firebase sdk npm package in a react-native project

Recently, I encountered a challenge with my firebase firestore. After some research, I discovered that reverting the version from 7.9.1 to 7.8.2 should fix the issue. npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail=" ...

Encountering a NPM Error while trying to install packages for a fresh project

Yesterday everything was working perfectly fine with installing packages from a project, but today I encountered an error. I attempted to install packages from another project and it seems to work without any issues. I haven't made any changes from ye ...

How can I initiate npm start in debug mode for create-react-app?

I've been facing an issue with create-react-app where it constantly gets stuck at starting the development server when I run npm start. The console remains empty and the process just appears to be running indefinitely without any progress. I suspect i ...

Executing the npm run test command with the unsafe-perm flag within the lifecycle phase

My React/Redux app is working fine, but whenever I run the command below: npm run test An error occurs as shown below: 6 info lifecycle [email protected]~test: [email protected] 7 verbose lifecycle [email protected]~test: unsafe-perm in li ...

Error encountered while setting up dependencies on VPS due to SQLite problem

I am currently in the process of hosting a Discord bot developed in TypeScript on my VPS provided by galaxygate, running Ubuntu 20.04. Fortunately, Git was already installed on the server, so I cloned and pulled my project from GitHub. Next, I attempted t ...