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

Error loading css modules in vite 4.4.8+

Open aleksolutions opened this issue 1 year ago • 4 comments

When I try to upgrade vite to a version higher than 4.4.7, after building the extension, the following messages appear in the console and cause the application to crash:

Error: Unable to preload CSS for /assets/index-1bdef0a0.css
    at HTMLLinkElement.<anonymous> (index-99ddc666.js:19:1496)

I'm using tailwind, but I have tried with a random css module and the same thing happens.

As usually, the extension works correctly in development mode.

aleksolutions avatar Aug 17 '23 15:08 aleksolutions

@samrum still with the same problem, do you still support this plugin?

aleksolutions avatar Oct 17 '23 12:10 aleksolutions

Can you create a small repo that reproduces the issue?

samrum avatar Oct 24 '23 17:10 samrum

I faced with the same issue.

When I run vite build through npm command like npm run build I have this stuff in getCssAssetInfoFromBundle method: assetFileName: "public/toastr/toastr.min.css" Bundle object: image

But when I run it via just vite build command in console: assetFileName: "public/toastr/toastr.min.css" I cant run debugger from console, so I just console logged all bundle names. Bundle object has value with this name: image "public/toastr/toastr.min.css"

Seems like vite cleans extension somehow if you build through npm command.

TheEZIC avatar Jan 28 '24 16:01 TheEZIC

Avoid using dynamic imports import('path/myscript.js') in your content script to import scripts, as this can lead to incorrect import paths in production environments. Instead, send a message to your service worker from the content script to execute additional JavaScript files:

  1. send a message to your service worker from your content script instead to run any addtional js files:
    browser.scripting.executeScript({
      target: { tabId: sender.tab.id },
      files: ['path/myscript.js'],
    });
  1. Also, ensure to include the path to the additional JavaScript file (path/myscript.js) in your vite.config.js configuration:
webExtension({
 // other configuration options
 additionalInputs: {
   styles: [...],
   html: [...],
   scripts: [
     // Add the path to your additional script here
     "path/myscript.js",
   ],
 },
}),

Hope this helps 😉

hamedbaatour avatar Jun 21 '24 19:06 hamedbaatour