arnoson / vite-plugin-live-reload

A simple live reloading plugin for vite.
86 stars 3 forks source link

Error start. TypeError: liveReload is not a function #7

Closed kviron closed 2 years ago

kviron commented 2 years ago

I am building a new project: npm create vite@latest --template vanilia

The vite.config file.js

import liveReload from 'vite-plugin-live-reload'

export default {
  plugins: [
    liveReload('./**/*.php'),
  ]
}

I am executing the command of the npm run dev I get an error:

failed to load config from D:\OpenServer\domains\sage.loc\html\app\themes\drozzi-theme\vite.config.js
error when starting dev server:
TypeError: liveReload is not a function
    at file:///D:/OpenServer/domains/sage.loc/html/app/themes/drozzi-theme/vite.config.js?t=1657868630638:5:5
    at ModuleJob.run (internal/modules/esm/module_job.js:170:25)
    at async Loader.import (internal/modules/esm/loader.js:178:24)
    at async loadConfigFromFile (file:///D:/OpenServer/domains/sage.loc/html/app/themes/drozzi-theme/node_modules/vite/dist/node/chunks/dep-561c5231.js:62653:31)
    at async resolveConfig (file:///D:/OpenServer/domains/sage.loc/html/app/themes/drozzi-theme/node_modules/vite/dist/node/chunks/dep-561c5231.js:62281:28)
    at async createServer (file:///D:/OpenServer/domains/sage.loc/html/app/themes/drozzi-theme/node_modules/vite/dist/node/chunks/dep-561c5231.js:58899:20)
    at async CAC.<anonymous> (file:///D:/OpenServer/domains/sage.loc/html/app/themes/drozzi-theme/node_modules/vite/dist/node/cli.js:699:24)
DoronTorangy commented 2 years ago

Happens to me as well. Here's a workaround until this is fixed:

For JS:

// vite.config.js
import liveReload from 'vite-plugin-live-reload'

export default defineConfig({
  plugins: [
      liveReload.default(['...'])
  ]
})

for TS:

// vite.config.js
import liveReload from 'vite-plugin-live-reload'

type LiveReloadFixType = typeof liveReload

export default defineConfig({
  plugins: [
    ((liveReload as any).default as LiveReloadFixType)(['...'])
  ]
})
arnoson commented 2 years ago

Will look at this in the next days, thank you for reporting the issue!

arnoson commented 2 years ago

I released a new version 3.0.0 that should fix this issue! Could you also test it and report if everyting is working as expected?

DoronTorangy commented 2 years ago

@arnoson I tested it right now, fixes the issue

kviron commented 2 years ago

Yes, the bug went away with version 3.0.0.

Everything is fine.

I wanted to ask. And it is possible to somehow connect the server proxying to a local domain, to develop a theme on a Wordpress cms.

I tried to use the server.proxy setting but I couldn't do anything. The plugin shows changes to php files in the console, but does not update the page.

I couldn't configure it in any way, maybe you had experience using Vite + Wordpress Theme

arnoson commented 2 years ago

I don't use Wordpress, but I use Vite together with Kirby CMS with a plugin. I don't think you need to proxy anything, just make sure that the vite client script is included in your HTML/PHP file during development.