vite-plugin-web-extension icon indicating copy to clipboard operation
vite-plugin-web-extension copied to clipboard

Make it compatible with vite V6

Open aleksolutions opened this issue 9 months ago • 8 comments

It would be great to upgrade to the latest version of vite and still be able to use this plugin.

aleksolutions avatar Feb 27 '25 19:02 aleksolutions

@aleksolutions , are you getting errors? I just upgraded to vite 6.2.2 and it seems to be working fine for me.

jdkdev avatar Mar 18 '25 14:03 jdkdev

@jdkdev I don't have any errors compiling but in dev mode.

 VITE v6.2.2  ready in 251 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  ➜  press h + enter to show help
node:internal/fs/promises:1202
    validateStringAfterArrayBufferView(data, 'data');
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined
    at writeFile (node:internal/fs/promises:1202:5)
    at DevBuilderManifestV3.writeManifestAssetFile (file:///C:/Users/alexs/projects/personal/node_modules/.pnpm/@samrum+vite-plugin-web-ext_49470b7512ed1e6a9268b937ec70ddec/node_modules/@samrum/vite-plugin-web-extension/dist/index.mjs:282:11)
    at async DevBuilderManifestV3.writeManifestContentCssFiles (file:///C:/Users/alexs/projects/personal/node_modules/.pnpm/@samrum+vite-plugin-web-ext_49470b7512ed1e6a9268b937ec70ddec/node_modules/@samrum/vite-plugin-web-extension/dist/index.mjs:261:9)
    at async DevBuilderManifestV3.writeBuild (file:///C:/Users/alexs/projects/personal/node_modules/.pnpm/@samrum+vite-plugin-web-ext_49470b7512ed1e6a9268b937ec70ddec/node_modules/@samrum/vite-plugin-web-extension/dist/index.mjs:159:5)
    at async ManifestV3.writeDevBuild (file:///C:/Users/alexs/projects/personal/node_modules/.pnpm/@samrum+vite-plugin-web-ext_49470b7512ed1e6a9268b937ec70ddec/node_modules/@samrum/vite-plugin-web-extension/dist/index.mjs:473:5) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Aleksnako avatar Mar 22 '25 15:03 Aleksnako

humm... some differences between our setups is I'm using npm and linux and looks like you're one pnpm/Windows.

Not sure what would cause the issue, can you share your vite config?

jdkdev avatar Mar 25 '25 13:03 jdkdev

Happens the same in linux/macos.

Here is my vite config:

import webExtension from '@samrum/vite-plugin-web-extension'
import react from '@vitejs/plugin-react'
import { resolve } from 'path'
import { defineConfig, loadEnv } from 'vite'
import zipPack from 'vite-plugin-zip-pack'

import pkg from './package.json'
import { getManifest } from './src/manifest'

export type Browser = 'chrome' | 'firefox' | undefined

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '')
  const browser = (env.BROWSER ?? 'chrome') as Browser
  const shouldZip = env.ZIP === 'true'
  const extensionVersion = pkg.version

  return {
    base: '',
    css: {
      preprocessorOptions: {
        scss: {
          api: 'modern-compiler'
        }
      }
    },
    resolve: {
      alias: {
        '@': resolve(__dirname, './src')
      }
    },
    server: {
      cors: {
        methods: 'GET',
        origin: '*'
      }
    },
    plugins: [
      react(),
      webExtension({
        manifest: getManifest(browser),
        useDynamicUrlWebAccessibleResources: false
      }),
      shouldZip &&
        zipPack({
          outDir: 'releases',
          outFileName: `${browser}-release-${extensionVersion}.zip`
        })
    ]
  }
})

aleksolutions avatar Mar 26 '25 21:03 aleksolutions

what does src/manifest file look like?

jdkdev avatar Apr 03 '25 17:04 jdkdev

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received undefined

I have the same error in dev, fixed by downgrading vite to 5.x.

T0RNATO avatar May 12 '25 12:05 T0RNATO

Works fine for me on vite 6.2.2. However, I'm not using pnpm . I've tried Vanilla, React, TypeScript options, everything compiles and runs with no errors.

yureitzk avatar Sep 01 '25 23:09 yureitzk

I see this too. Just upgraded to [email protected]. Using npm, manifest defined in TS. I have a TS error in vite.config.ts (defineConfig):

Type 'import("/my-ext/path/node_modules/@samrum/vite-plugin-web-extension/node_modules/vite/dist/node/index").PluginOption' is not assignable to type 'import("/my-ext/path/node_modules/vite/dist/node/index").PluginOption'.
  Type 'PluginOption[]' is not assignable to type 'PluginOption'

andyghiuta avatar Oct 15 '25 06:10 andyghiuta