Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error loading css modules in vite 4.4.8+ #126

Open
aleksolutions opened this issue Aug 17, 2023 · 4 comments
Open

Error loading css modules in vite 4.4.8+ #126

aleksolutions opened this issue Aug 17, 2023 · 4 comments

Comments

@aleksolutions
Copy link

aleksolutions commented Aug 17, 2023

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
Copy link
Author

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

@aleksolutions aleksolutions changed the title Error loading css modules in vite 4.0.8+ Error loading css modules in vite 4.4.8+ Oct 18, 2023
@samrum
Copy link
Owner

samrum commented Oct 24, 2023

Can you create a small repo that reproduces the issue?

@TheEZIC
Copy link

TheEZIC commented Jan 28, 2024

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.

@hamedbaatour
Copy link

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 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants