question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

new URL() emits an extra blank css file

See original GitHub issue
  • Operating System: Ubuntu Linux 16.04 LTS
  • Node Version: 14.15.0
  • NPM Version: 6.14.8
  • webpack Version: 5.44.0
  • mini-css-extract-plugin Version: 2.1.0

Expected Behavior

css should be extracted cleanly into a css bundle without emitting artifacts

Actual Behavior

css is extracted into bundle but a bogus css file is also emitted

Code

// webpack.config.js

import CssPlugin from "mini-css-extract-plugin";

export default {
	entry: { app: "./src/test-new-url.js" },
	mode: "development",
	module: {
		rules: [
			{
				test: /\.css$/,
				use: [CssPlugin.loader, "css-loader"]
			}
		]
	},
	output: { filename: "[name].js" },
	plugins: [new CssPlugin({ filename: "[name].css" })]
};
// src/test-new-url.js

new URL("./test-new-url.css", import.meta.url);
/* src/test-new-url.css */

body {
	font-size: 14px;
}

How Do We Reproduce?

Place the three files in an environment and build. You will get the following files in dist: app.js app.css (contains the correct, extracted css) b88d04fba731603756b1.css (your hash may vary) which contains the following:

// extracted by mini-css-extract-plugin
export {};

This is the bogus file. The bogus file does not get emitted with a standard import import "./src/test-new-url.css";

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
alexander-akaitcommented, Jul 21, 2021

@GregNing Please create reproducible test repo

0reactions
alexander-akaitcommented, Sep 6, 2021

Original issues can be solved using type: 'javascript/auto', i.e.

module.exports = {
  entry: "./index.js",
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [Self.loader, "css-loader"],
        type: 'javascript/auto'
      },
    ],
  },
  plugins: [
    new Self({
      filename: "[name].css",
    }),
  ],
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why css file is loading a blank page? - html - Stack Overflow
I'm not sure whether you've not added it here on SO, but your HTML file doesn't contain anything to show. (no <body></body> or...
Read more >
url() - CSS: Cascading Style Sheets - MDN Web Docs
The url() CSS function is used to include a file. The parameter is an absolute URL, a relative URL, a blob URL, or...
Read more >
Emit new Page objects when new tabs created #386 - GitHub
A nice feature would be if the browser emit an event with a new Page when a new tab is opened by clicking...
Read more >
Safari Technology Preview Release Notes - Apple Developer
Added emulation toggles for prefers-reduced-motion and prefers-contrast CSS media features (257197@main); Fixed corrupted styles when adding a new property ...
Read more >
webContents | Electron
explicitSet is false when title is synthesized from file url. ... Emitted when there is a new context menu that needs to be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found