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

[v3.0.2] Plugin.prototype.readFile this.outputs[file] undefined because of OS path separator #349

Closed
klmdb opened this issue Sep 3, 2018 · 7 comments

Comments

@klmdb
Copy link

klmdb commented Sep 3, 2018

going from 2.x to 3.x, the code became dependent on os path separator:

2.0.13

middleware.fileSystem.readFile(path.join(os.tmpdir(), '_karma_webpack_', String(idx), file.replace(/\\/g, '/')), callback)
//...
var fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', file.replace(/\\/g, '/')))

3.0.2

middleware.fileSystem.readFile(path.join(os.tmpdir(), '_karma_webpack_', String(idx), this.outputs[file]), callback)
//...
var fileContents = middleware.fileSystem.readFileSync(path.join(os.tmpdir(), '_karma_webpack_', this.outputs[file]))

this.outputs[file] should be this.outputs[file.replace(/\\/g, '/')]

@michael-ciniawsky
Copy link
Contributor

michael-ciniawsky commented Sep 3, 2018

Could you try with path.posix.join or a small helper

const normalize = (file) => file.split(path.sep).join('/')
...
... this.outputs[normalize(file)] ...

I'm assuming your are on windows, right? Otherwise please elaborate in more detail what doesn't work please (Actual/Expected)

@michael-ciniawsky michael-ciniawsky added this to the 3.0.2 milestone Sep 3, 2018
@michael-ciniawsky michael-ciniawsky changed the title v3.0.2: Plugin.prototype.readFile this.outputs[file] undefined because of OS path separator [v3.0.2] Plugin.prototype.readFile this.outputs[file] undefined because of OS path separator Sep 3, 2018
@klmdb
Copy link
Author

klmdb commented Sep 3, 2018

Yes I am on Windows.

@ghost
Copy link

ghost commented Sep 3, 2018

Running karma-webpack on Windows results in the following error message on 3.0.2:

ERROR [karma]: [TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined

Running on 2.0.0 works.
The problem seems to be that this.outputs is indexed with paths using forward slash separators while backslash separators are not replaced in the indexing string. This means every reference to files in different directories on windows-machines throws an error.

@Javi
Copy link

Javi commented Sep 7, 2018

Can confirm, just got bit by this on Windows and making paths like [`folder${path.delimiter}file.js`] makes it work.

@nomve
Copy link

nomve commented Sep 7, 2018

@nomve
Copy link

nomve commented Sep 7, 2018

downgrading to 3.0.0 also works for me

@michael-ciniawsky
Copy link
Contributor

Fixed by #353, released in v3.0.3 🎉

@michael-ciniawsky michael-ciniawsky removed this from the 3.0.4 milestone Sep 7, 2018
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

4 participants