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

Broken on Windows #22

Closed
gaearon opened this issue Dec 8, 2016 · 15 comments
Closed

Broken on Windows #22

gaearon opened this issue Dec 8, 2016 · 15 comments

Comments

@gaearon
Copy link
Contributor

gaearon commented Dec 8, 2016

We integrated this plugin into Create React App (facebook/create-react-app#1202), and the build breaks on Windows:

To reproduce:

npm i -g create-react-app
create-react-app myapp --scripts-version 0.8.2

cd myapp
npm run build

This happens on Windows because the generated compilation assets key contains Windows path separators but Webpack expected a normalized one.

@jscheid
Copy link
Collaborator

jscheid commented Dec 8, 2016

Released in v0.8.1. Sorry about that, we're not using Windows here and it didn't occur to anybody to test with it :-/

I'm planning to setup CI on Windows soon, perhaps with Appveyor.

@gaearon
Copy link
Contributor Author

gaearon commented Dec 8, 2016

Sounds great! We don’t test CI on Windows either but we should :-/

@jantimon
Copy link

jantimon commented Dec 8, 2016

Wow cool now it is part of create react app? :)

@gaearon
Copy link
Contributor Author

gaearon commented Dec 8, 2016

Yea!

@chenEdgar
Copy link

I reproduced this question on window8.1.
I used webpack 1.13.2 and html-webpack-plugin with injected true.
qq 20170515200340

@jscheid
Copy link
Collaborator

jscheid commented May 15, 2017

@chenEdgar it does look like the same issue, but that issue was fixed (and we are now running the test suite on Windows) so it's more likely something unrelated. Perhaps it would be better if you opened a new issue.

I'll need more information to see what's going on, did you see this? https://github.com/waysact/webpack-subresource-integrity/blob/master/CONTRIBUTING.md#issues

Does it work with the current stable version of webpack-subresource-integrity (0.9.0)?

Do you have a way to test on a Unix-ey system (Linux or MacOS perhaps) and see if it works there?

Could you add debug output (before this line

return compilation.assets[src].integrity;
) so that we can know the values of src and of Object.keys(compilation.assets)?

@sebastiandemel
Copy link

sebastiandemel commented Sep 19, 2017

I had the same problem that was caused by the css file (value: src) missing from the compilation assets (compilation.assets).

What I did was that I changed line the plugins index.js:326 to
return src in compilation.assets ? compilation.assets[src].integrity : false;

This caused a correct warning in the output:
WARNING in webpack-subresource-integrity: Cannot determine hash for asset 'css/app.xxxxxxx.css', the resource will be unprotected.

Pull request created

@sebastiandemel
Copy link

This however doesn't explain why in my case it is caused by the css file.

@sebastiandemel
Copy link

sebastiandemel commented Sep 29, 2017

Found the reason why our css was crashing:

Log
index.js:325 - Assets for type: css: [ ....'css\\app.xxxx.css' ...]
index.js:168 - hwpAssetPath::parameter src= /css\app.xxxx.css
index.js:331 - variable filePath = /css\app.xxxx.css
index.js:332 - variable src = css/app.xxxx.css

When the filePath (/css\app.xxxx.css) enters hwpAssetPath it comes out as css/app.xxxx.css
This however doesn't match the compilation.assets css\\app.xxxx.css

The bug now being that for some reason compilation.assets has a 'css\\' that is wrong (all js files are in the form js/) causing the hwpAssetPath output not to match with the one found in compilation.assets

@jscheid
Copy link
Collaborator

jscheid commented Sep 29, 2017

Thanks for investigating with this, @WallRushGO! I think with this info I'll be able to reproduce it. I'll have a closer look at this over the next few days.

@sebastiandemel
Copy link

sebastiandemel commented Sep 29, 2017

The root cause for us was to use the path.join in ExtractTextPlugin

config.build.mapping.styles = './css'

const extractCSS = new ExtractTextPlugin({
    filename: utils.assetsPath(path.join(config.build.mapping.styles, '[name].[contenthash:7].css'))
})

Our fix

const extractCSS = new ExtractTextPlugin({
    filename: utils.assetsPath([config.build.mapping.styles, '[name].[contenthash:7].css'].join('/'))
})

@jscheid
Copy link
Collaborator

jscheid commented Sep 29, 2017

Ah, good to know, but I'd call this a workaround and not a fix. I'm aiming to release a fix for this soon and you'll be able to go back to using path.join.

@bzbetty
Copy link

bzbetty commented Nov 6, 2017

I'm using ExtractTextPlugin("styles.css?[contenthash]");

so for me it appears to be searching for

styles.css?b201f92da5f06ce3a6eb8816602e1230&cd9dfb6f4017ef825e33

but the compilation.assets dictionary only contains an entry for

styles.css?b201f92da5f06ce3a6eb8816602e1230

unsure if this is totally related to this particular issue, but I am running this on windows and it also seems to be css + extract text related as @WallRushGO 's problem was.

jscheid added a commit that referenced this issue Dec 4, 2017
jscheid added a commit that referenced this issue Dec 4, 2017
@jscheid jscheid reopened this Dec 4, 2017
jscheid added a commit that referenced this issue Dec 4, 2017
When there is no direct match for an asset path, search for it by
comparing normalized paths where the query part is stripped and (on
Windows) backslashes are replaced by forward slashes.

Closes #22
@bruno bruno closed this as completed in #56 Dec 6, 2017
@jscheid
Copy link
Collaborator

jscheid commented Dec 6, 2017

@WallRushGO @bzbetty both should be fixed in v1.0.3, let me know how it works for you.

@bzbetty
Copy link

bzbetty commented Jan 19, 2018

yep works great now.

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

No branches or pull requests

6 participants