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

publicPath escapes '@' character while emitting css files #15012

Closed
jedrzejowski opened this issue Dec 17, 2021 · 14 comments
Closed

publicPath escapes '@' character while emitting css files #15012

jedrzejowski opened this issue Dec 17, 2021 · 14 comments
Labels
bug dependencies Pull requests that update a dependency file inactive webpack-5

Comments

@jedrzejowski
Copy link

Bug report

Hi, I'm developing chrome extension and in order to use images in CSS styles i need to set pubicPath to chrome-extension://__MSG_@@extension_id__/ (see why).

What is the current behavior?

For unknown reason CSS files are generated like this:

body {
    background: red;
    background-image: url(chrome-extension://__MSG_%40@extension_id__/895c2722a512d5b2e333.png);
/*                                                 ^^^                                           */
}

If the current behavior is a bug, please provide the steps to reproduce.

I prepared repository:

git clone git@github.com:jedrzejowski/my-issue-3.git webpack-issue-XXX
cd webpack-issue-XXX
npm ci
npx webpack
cat dist/index.css 

What is the expected behavior?

CSS file should look like this:

body {
    background: red;
    background-image: url(chrome-extension://__MSG_@@extension_id__/895c2722a512d5b2e333.png);
}

Other relevant information:
webpack version: 5.65.0, bug was introduced in version 5.52.0
Node.js version: 16/17
Operating System: Linux
Additional tools: none

@jedrzejowski jedrzejowski changed the title publicPath escapes '@' character publicPath escapes '@' character while emitting css files Dec 17, 2021
@alexander-akait
Copy link
Member

Why you use @@? They are stripped, try to run new URL("chrome-extension://__MSG_@extension_id__/895c2722a512d5b2e333.png") in browser

@jedrzejowski
Copy link
Author

jedrzejowski commented Dec 17, 2021

VVV This does not work VVV
image

VVV This does work VVV
image

I don't to call this URL via JavaScript. I want to create styles with this URL.

Chrome extensions changes those URLs by themselves in runtime, see here. That is why i need @@.

@jedrzejowski
Copy link
Author

I know this is edge case, but can be there any way to prevent Webpack from messing with publicPath?

@alexander-akait
Copy link
Member

I'm afraid not, I am investigating this problem now. Yes you don't run new URL(...), but we use this construction for creating url() and then run it on Node.js side

@alexander-akait
Copy link
Member

alexander-akait commented Dec 17, 2021

current workaround - disable ESM generation:

{
  loader: "css-loader",
  options: {
    esModule: false,
  }
}

@alexander-akait
Copy link
Member

alexander-akait commented Dec 17, 2021

Oh, bug on Node.js side.

Run console.log(new URL("chrome-extension://__MSG_@@extension_id__/895c2722a512d5b2e333.png")) in browser and run console.log(new URL("chrome-extension://__MSG_@@extension_id__/895c2722a512d5b2e333.png")) on Node.js side, output is different

@alexander-akait
Copy link
Member

alexander-akait commented Dec 17, 2021

In browser:

URL {origin: 'chrome-extension://extension_id__', protocol: 'chrome-extension:', username: '', password: '', host: 'extension_id__', …}
hash: ""
host: "extension_id__"
hostname: "extension_id__"
href: "chrome-extension://extension_id__/895c2722a512d5b2e333.png"
origin: "chrome-extension://extension_id__"
password: ""
pathname: "/895c2722a512d5b2e333.png"
port: ""
protocol: "chrome-extension:"
search: ""
searchParams: URLSearchParams {}
username: ""
[[Prototype]]: URL

In Node.js

URL {
  href: 'chrome-extension://__MSG_%40@extension_id__/895c2722a512d5b2e333.png',
  origin: 'null',
  protocol: 'chrome-extension:',
  username: '__MSG_%40',
  password: '',
  host: 'extension_id__',
  hostname: 'extension_id__',
  port: '',
  pathname: '/895c2722a512d5b2e333.png',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

@alexander-akait
Copy link
Member

hm, firefox output is different too:

URL { href: "chrome-extension://__MSG_@@extension_id__/895c2722a512d5b2e333.png", origin: "null", protocol: "chrome-extension:", username: "", password: "", host: "", hostname: "", port: "", pathname: "//__MSG_@@extension_id__/895c2722a512d5b2e333.png", search: "" }
hash: ""
host: ""
hostname: ""
href: "chrome-extension://__MSG_@@extension_id__/895c2722a512d5b2e333.png"
origin: "null"
password: ""
pathname: "//__MSG_@@extension_id__/895c2722a512d5b2e333.png"
port: ""
protocol: "chrome-extension:"
search: ""
searchParams: URLSearchParams {  }
username: ""
<prototype>: URLPrototype { toJSON: toJSON(), toString: toString(), href: Getter & Setter, … }

@jedrzejowski
Copy link
Author

workaround with esModule: false works fine

@alexander-akait
Copy link
Member

Reported nodejs/node#41220

@alexander-akait alexander-akait added bug dependencies Pull requests that update a dependency file webpack-5 labels Dec 17, 2021
@webpack-bot
Copy link
Contributor

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

@vankop
Copy link
Member

vankop commented Apr 3, 2022

@alexander-akait so should we keep closed this?

@alexander-akait
Copy link
Member

@vankop Not sure, there is different behavior in chrome (in firefox too and another) and Node.js and all says they have valid logic 😕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug dependencies Pull requests that update a dependency file inactive webpack-5
Projects
None yet
Development

No branches or pull requests

4 participants