partytown icon indicating copy to clipboard operation
partytown copied to clipboard

[🐞] Vite - Failed to load url /~partytown/partytown.js

Open kouts opened this issue 1 year ago • 4 comments

Describe the bug

I have included Partytown for Vite using the supplied instructions in the docs.

index.html

<script src="/~partytown/partytown.js"></script>

vite.config.js

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { join, resolve } from 'path'
import { partytownVite } from '@builder.io/partytown/utils'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    partytownVite({
      dest: join(__dirname, 'dist', '~partytown'),
    }),
  ],
  resolve: {
    alias: [
      {
        find: /^@\/(.+)/,
        replacement: resolve(__dirname, 'src') + '/$1',
      },
    ],
  },
})

Although the partytown script gets loaded, I get an error in the terminal while in dev mode: Failed to load url /~partytown/partytown.js (resolved id: /~partytown/partytown.js). Does the file exist?

Reproduction

https://stackblitz.com/edit/vue3-script-setup-with-vite-h2k23d

Steps to reproduce

Just visit the reproduction in this Stackblitz here. You should see the error in the terminal

Browser Info

Browser agnostic

Additional Information

image

kouts avatar Jul 04 '23 06:07 kouts

It does not look like you are serving that /~partytown/partytown.js from your setup. You need to configure your server to serve those filse.

mhevery avatar Aug 02 '23 09:08 mhevery

This is the Vite dev server running, any idea how to configure it properly?

kouts avatar Aug 02 '23 10:08 kouts

Same issue, but when I open it in the browser the script is located.

I'm using the path /partytown.js

// vite.config.ts

export default defineConfig({
	plugins: [
		vue(),
		vueJsx(),
		partytownVite({
			dest: path.join(__dirname, "dist", "~partytown")
		}),
	],
});
// index.html 

<head>
	<script>
		partytown = {
			debug: true,
		}
	</script>
	
	<script src="/partytown.js"></script>
</head>

mateusfmello avatar Feb 11 '24 18:02 mateusfmello

Same issue here, partytownVite doesn't seem to copy files

fromaline avatar May 02 '24 13:05 fromaline