kulmacet's avatar

Vite: I bet this has been answered

I am having issues deploying my production server using Vite:

 #> npm run build

> build
> vite build

/opt/sites/projectName/node_modules/vite/bin/vite.js:2
import { performance } from 'node:perf_hooks'
       ^

SyntaxError: Unexpected token {
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)

Any support appreciated. Regards, Kulmacet

0 likes
26 replies
Sinnbeck's avatar

What node version are you running on production? Maybe its running to old a version. I use node 16 myself

kulmacet's avatar

Thanks for the quick relpy. I'm using the latest:

node -v
v18.10.0

I may try and down rev to 16 and give it a whirl.

kulmacet's avatar

Seems there is very little help or support with Vite (How to deploy). I'm sure it's something I'm doing

1 like
Sinnbeck's avatar

@kulmacet we are all kinda new to vite. Sadly I haven't seen that error before and Google does not find any hits. Helping you deploy. Sure we can help you with that. Finding the reason for some obscure node error with 0 hits on Google (and which I personally have never seen before) is another matter. If you could help us recreate it, then that might be another matter.

Did you give node 16 a try?

kulmacet's avatar

yeah, ver 16 didn't work.

The struggle continues. This will be a simple fix. Thank goodness this is not a production site. That would be bad.

Niush's avatar

@kulmacet Try clearing Vite cache by deleting node_modules/.vite directory. Then, update Vite npm package and, re-run the build command.

Also, is there any modification to vite.config file?

Sinnbeck's avatar

@kulmacet does it work locally? Maybe you can compile locally and add the files to git?

kulmacet's avatar

@niush there has been no change the vite.config I will try and clear the cache but I have totally wiped the installation and started over but still no joy.

kulmacet's avatar

Apologies for the rant been working this issue for 2 days+ , The issue is stuck if this was production a lot of people would be mad. Freaks me out that Laravel went from webpack to Vite because it is better (I'm not sure I have seen that yet), and to make such a change inside the major version. My projects (Most projects) aren't that large but here run Vite and have another server running while you develop. There should have been a choice use Vite or WebPack but there wasn't. Here swallow this "GULP!" (It's better) and now I have a project that doesn't work and I'm not sure I'm going to get past this. I will stay the course and continue working the issue and find that one little check box that needs to be selected to make everything work. "CRAZY! and unimpressed"

1 like
ApexLeo's avatar

@kulmacet vite is not stable and not suitable for laravel right now. just because it is fast doest mean they just need to implement it now. this is a blunder thay did in laravel project. unlike you, i used it in production project though i have backup but thats not the point and also whats the point of using vite when u eventually have to get back to webpack and change you project according to it.

maogu's avatar

When I use macbook its working , When I upload to ubuntu server still i get above error,

1 like
designpond's avatar

Hi, I had the same issue on DigitalOcean and managed to solve it by adding the correct permissions on the node_modules folder and the public folder. Hope this helps.

ovimax's avatar

Hi, I had the same problem recently, and I solve it by changing the Node version, I used Node v14

kulmacet's avatar

Wow, wee! The hits they just keep on a coming. I hope Taylor made a lot of money with shite, I mean vite. error when starting dev server: Error: EPERM: operation not permitted, scandir

thinkverse's avatar

@kulmacet, sorry you're having issues with Vite, but why are you dumping on Taylor? He has nothing to do with the development of Vite. It was created and is run by Evan You, the person who created Vue.

BluKoffee's avatar

I solved the issue by updating my node version to version 18 after installing and with the help of nvm on ubuntu the npm was then updated along with the installation of node

sanjayacloud's avatar

If you guys are using docker tries to run sail npm install instead of npm install. It worked for me.

alden8's avatar

Node v 16.19.0 solve this problem for me.

P.S. If after that there is also such a problem

Error: ENOSPC: System limit for number of file watchers reached, watch '/home/admin/web/orders-crud.alenev.name/public_html/vendor/laravel/framework/src/Illuminate/Routing/Console/stubs/controller.model.api.stub'

The following fix of Linux parameters will also be needed:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
llyupll's avatar

changing to node version 18 worked for me 👍

shllghst's avatar

I was having the exact same error. This is what solves the error :

npm uninstall vite
npm install --save-dev vite

So basically, reinstalling vite.

1 like
Stavros's avatar

@shllghst Thnx that worked!

my 50cents here, this happen when I tried to duplicate a project via cp -r. New projects are fine (node 19 etc)

scritrolf's avatar

@Stavros Thanks! This was just the thought I needed, after several failed attempts to get a duplicated project working again :) Just deleted node_modules and npm i, then all was fine :)

RobSaunders's avatar

Good evening. I have just run into this issue myself and managed to fix it by using Node Version 18 as follows:

nvm install 18 (when download and install is complete, just check it's switched you to use v18) npm install -D npm run dev

You'll need to switch versions as required on other projects so just keep it in mind

I hope this is of some use to anyone :-)

Please or to participate in this conversation.