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

TypeError: Path must be a string. Received [ 'js/main.spec.js', #350

Closed
casufi opened this issue Sep 3, 2018 · 36 comments
Closed

TypeError: Path must be a string. Received [ 'js/main.spec.js', #350

casufi opened this issue Sep 3, 2018 · 36 comments

Comments

@casufi
Copy link

casufi commented Sep 3, 2018

x「wdm」: wait until bundle finished: noop 03 09 2018 10:51:35.026:ERROR [karma]: TypeError: Path must be a string. Received [ 'js/main.spec.js', 'css/tiscc.min.css', 'js/main.spec.js.map', 'css/tiscc.min.css.map' ] at assertPath (path.js:28:11) at Object.join (path.js:1236:7) at Plugin.<anonymous> (/builds/tis/tis/tiscommandcenter/node_modules/karma-webpack/lib/karma-webpack.js:262:68) at Plugin.readFile (/builds/tis/tis/tiscommandcenter/node_modules/karma-webpack/lib/karma-webpack.js:281:5) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickCallback (internal/process/next_tick.js:180:9)

  • Operating System: Windows 10
  • Node Version: v8.11.3
  • NPM Version: 6.4.0
  • webpack Version: 4.17.1
  • karma-webpack Version: 3.0.2

Code

https://gist.github.com/casufi/f298bcab3f2f95a82616591446e380de

How Do We Reproduce?

@rythos42
Copy link

rythos42 commented Sep 3, 2018

I'm brand new to using karma-webpack and ran into this issue yesterday while trying to set up my environment. Is there a version that would be better to use, while this gets looked at? Thanks!

@nstepien
Copy link

nstepien commented Sep 3, 2018

@rythos42 3.0.0 is working fine for me.

@yibn2008
Copy link

yibn2008 commented Sep 4, 2018

+1 I also found this bug, I've fallback to 3.0.0.

@vladimiry
Copy link

Facing the same error running [email protected] on Windows OS, see output here.

[email protected] doesn't have such problem, but it requires this workaround.

@npetruzzelli
Copy link

npetruzzelli commented Sep 5, 2018

the problem is it is this line:

https://github.com/webpack-contrib/karma-webpack/blob/d2f5a538d864e7b1f4bb431324de67be1ccbb51d/src/karma-webpack.js#L255

The problem is not line 255 itself, that is just where it occurs.

file is a file system path that is normalized to the operating system, meaning the path seperator on Windows is \ BUT the keys in this.outputs always uses the forward slash / regardless of the operating system. so the result of this.outputs[file] will always be undefined.

This will always be a problem on Windows. It will just happen to work on POSIX systems, but its fragile.

It appears this is a new issue. I was recently using 3.0.0 without any problems, when someone went to review my code "karma-webpack": "^3.0.0" in package.json resolved to 3.0.2 and the errors started.

@lusarz
Copy link

lusarz commented Sep 6, 2018

I've also met this (or similar) issue. In my case it occured when I was using karma in autowatch mode. The value of this.outputs[file] was an array:

[
  'javascript/index.bundle.js',
  '46.0848c6149c8de4ab841b.hot-update.js' 
]

@43081j
Copy link

43081j commented Sep 6, 2018

This can be encountered if a preprocessor beforehand has already produced multiple outputs, too.

For example, sourcemaps preprocessing will result in ['foo.js', 'foo.js.map'].

@npetruzzelli
Copy link

npetruzzelli commented Sep 6, 2018

this.outputs appears 6 places in the file. I haven't finished looking through it, so I don't know what the impact of what I am about to suggest is (yet).

https://github.com/webpack-contrib/karma-webpack/blob/d2f5a538d864e7b1f4bb431324de67be1ccbb51d/src/karma-webpack.js#L125-L133

console.log(this.entries);
/* =>
{
    'apps\\front-end\\src\\_assets\\debug\\root.spec': 'apps/front-end/src/_assets/debug/root.spec.tsx',
    'apps\\front-end\\src\\_assets\\main\\main.spec': 'apps/front-end/src/_assets/main/main.spec.tsx'
}
*/

console.log(entry);
// => "apps\\front-end\\src\\_assets\\main\\main.spec"
// NOTE: the file extension `.tsx` is not present

console.log(entryPath);
// => "apps/front-end/src/_assets/main/main.spec.tsx"

// ... later in the file

console.log(file);
// => "apps\\front-end\\src\\_assets\\main\\main.spec.tsx"

console.log(this.outputs);
/* =>
{
    'apps/front-end/src/_assets/debug/root.spec.tsx': [
        '_assets/bundles/apps\\front-end\\src\\_assets\\debug\\root.spec/apps\\front-end\\src\\_assets\\debug\\root.spec.js',
        '_assets/bundles/apps\\front-end\\src\\_assets\\debug\\root.spec/apps\\front-end\\src\\_assets\\debug\\root.spec.js.map'
    ],
    'apps/front-end/src/_assets/main/main.spec.tsx': [
        '_assets/bundles/apps\\front-end\\src\\_assets\\main\\main.spec/apps\\front-end\\src\\_assets\\main\\main.spec.js',
        '_assets/bundles/apps\\front-end\\src\\_assets\\main\\main.spec/apps\\front-end\\src\\_assets\\main\\main.spec.js.map'
    ]
}
*/

// For context, here is a relevant portion of the webpack configuration:
/*
{
...
    output: {
        path: PATH_TO_DIST,
        publicPath: '/',
        filename: IS_PRODUCTION_ENV
            ? '_assets/bundles/[name]/[name].[hash:20].js'
            : '_assets/bundles/[name]/[name].js'
    }
...
}
*/

A change similar to this might fix the issue:

           var entryPath = this.entries[entry]
           var outputPath = stats.assetsByChunkName[entry]
-          this.outputs[entryPath] = outputPath
+          var entryPathNormalized = entryPath.replace(/\//g, path.sep)
+          this.outputs[entryPathNormalized] = outputPath

path.normalize() does more than handle the path separator, so I'm not sure if it should be used instead or not.

The above is a first step, the final fix may be more involved.

@npetruzzelli
Copy link

I took another look at the original post. It looks like my issue is separate (but similar) to this one, where instead of receiving an unexpected array (like the OP), it is receiving undefined, which is also an invalid argument for the path.join() method as used in lines 238 and 255.

@thijstriemstra
Copy link

thijstriemstra commented Sep 6, 2018

3.0.0 is working fine for me.

but this doesn't support webpack 4, does it? is there any workaround for webpack 4 users? this issue effectively broke all our CI builds/PRs.

@43081j
Copy link

43081j commented Sep 6, 2018

Yes, there are two issues.

One is the mismatch of path separators (#353 and #351 are related). Simple to fix.

The other is that chunks can have multiple assets so assetsByChunkName[entry] can be an array or a string (as per webpack's docs). This is not a simple fix as we can't really infer which of the assets is the code, unless we maybe pick the first .js entry.

edit:

@thijstriemstra webpack 4 and 3.0.0 do work together (its what im using now until these get fixed).

@ryanclark
Copy link
Collaborator

Will get a fix out asap

@nstepien
Copy link

nstepien commented Sep 6, 2018

@thijstriemstra well I'm on webpack ^4 and karma-webpack 3.0.0, and my tests run. ¯\_(ツ)_/¯

@thijstriemstra
Copy link

thijstriemstra commented Sep 6, 2018

@MayhemYDG oh damn, i'll try that, cheers.

Update: same results, wtf

> [email protected] test /home/thijs/projects/wavesurfer.js
> karma start karma.conf.js

(node:4394) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
    at Plugin.<anonymous> (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:109:14)
    at Array.forEach (<anonymous>)
    at Plugin (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:108:16)
    at invoke (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:75:15)
    at Array.instantiate (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:59:20)
    at get (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:48:43)
    at /home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:71:14
    at Array.map (<anonymous>)
    at Array.invoke (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:70:31)
    at Injector.get (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:48:43)
    at instantiatePreprocessor (/home/thijs/projects/wavesurfer.js/node_modules/karma/lib/preprocessor.js:50:20)
    at Array.forEach (<anonymous>)
    at createPreprocessor (/home/thijs/projects/wavesurfer.js/node_modules/karma/lib/preprocessor.js:68:20)
    at Array.invoke (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:75:15)
    at get (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:48:43)
    at /home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:71:14
ℹ 「wdm」: wait until bundle finished: noop
ℹ 「wdm」: wait until bundle finished: noop
ℹ 「wdm」: wait until bundle finished: noop
ℹ 「wdm」: wait until bundle finished: noop
06 09 2018 17:25:33.856:ERROR [karma]: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string
    at assertPath (path.js:39:11)
    at Object.join (path.js:1158:7)
    at Plugin.<anonymous> (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:262:68)
    at Plugin.readFile (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:281:5)
    at process._tickCallback (internal/process/next_tick.js:176:11)
06 09 2018 17:25:33.858:ERROR [karma]: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string
    at assertPath (path.js:39:11)
    at Object.join (path.js:1158:7)
    at Plugin.<anonymous> (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:262:68)
    at Plugin.readFile (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:281:5)
    at process._tickCallback (internal/process/next_tick.js:176:11)
06 09 2018 17:25:33.859:ERROR [karma]: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string
    at assertPath (path.js:39:11)
    at Object.join (path.js:1158:7)
    at Plugin.<anonymous> (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:262:68)
    at Plugin.readFile (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:281:5)
    at process._tickCallback (internal/process/next_tick.js:176:11)
06 09 2018 17:25:33.859:ERROR [karma]: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string
    at assertPath (path.js:39:11)
    at Object.join (path.js:1158:7)
    at Plugin.<anonymous> (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:262:68)
    at Plugin.readFile (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:281:5)
    at process._tickCallback (internal/process/next_tick.js:176:11)
ℹ 「wdm」: 
ℹ 「wdm」: Compiled successfully.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `karma start karma.conf.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

damencho added a commit to jitsi/lib-jitsi-meet that referenced this issue Sep 6, 2018
Could not update karma-webpack to latest as it was not running because of an error:
The "path" argument must be of type string. Received type object
codymikol/karma-webpack#350
damencho added a commit to jitsi/lib-jitsi-meet that referenced this issue Sep 7, 2018
Could not update karma-webpack to latest as it was not running because of an error:
The "path" argument must be of type string. Received type object
codymikol/karma-webpack#350
@nstepien
Copy link

nstepien commented Sep 7, 2018

@thijstriemstra I get the same error on karma-webpack 3.0.2.
Make sure you install version 3.0.0 exactly. Delete your node_modules and lock files, re-install your npm dependencies, and retry.

@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
@uncleramsay
Copy link

Er, I'm still getting the same error reported by the OP in 3.0.3

@43081j
Copy link

43081j commented Sep 7, 2018

@michael-ciniawsky only one of the two issues was fixed.

the other issue was that a source can have multiple assets so the output entry may be an array.

@michael-ciniawsky
Copy link
Contributor

michael-ciniawsky commented Sep 7, 2018

@43081j I'm semi-aware of the regression introduced by d2f5a53 and may need to revert it for now, but I need more info why it doesn't work. Could you please open a new issue elaborating on it?

@michael-ciniawsky
Copy link
Contributor

Released in v3.0.4 🎉

damencho added a commit to jitsi/lib-jitsi-meet that referenced this issue Sep 7, 2018
Could not update karma-webpack to latest as it was not running because of an error:
The "path" argument must be of type string. Received type object
codymikol/karma-webpack#350
@kirschre
Copy link

kirschre commented Sep 7, 2018

I'm still seeing the same issue on 3.0.4 (tests succeed on 3.0.0):

07 09 2018 12:30:23.322:ERROR [karma]: TypeError: Path must be a string. Received [ 'path/to/karma_index.bundle.js',
  'path/to/karma_index.bundle.js.map' ]
    at assertPath (path.js:28:11)
    at Object.join (path.js:1236:7)
    at Plugin.<anonymous> (path/to/node_modules/karma-webpack/lib/karma-webpack.js:266:68)
    at Plugin.readFile (path/to/karma-webpack/lib/karma-webpack.js:285:5)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
ℹ 「wdm」: Hash: 95085f23983f7eeef8e0
Version: webpack 4.17.2
Time: 22273ms
Built at: 2018-09-07 11:30:23

@thijstriemstra
Copy link

Note to maintainer: let us test your fixes first instead of putting out new buggy releases?

@michael-ciniawsky
Copy link
Contributor

michael-ciniawsky commented Sep 7, 2018

@thijstriemstra Sure, do you want to be the new maintainer of this plugin and write the tests ? 😛 I'm only administrating here...

@kirschre #355 (it's a different known bug, introduced by ab4dde9, e.g when using sourcemaps)

@thijstriemstra
Copy link

No but put out a release candidate for testing first. Oh well.

@nstepien
Copy link

nstepien commented Sep 7, 2018

Or revert regressions. 🤔

@JonUK
Copy link

JonUK commented Sep 10, 2018

I have also seen this issue with sourcemap generation disabled but with a JS file that imports SASS:

ERROR [karma]: TypeError: Path must be a string. Received [ 'src\components\person\person.test.css',
'src\components\person\person.test-bundle.js' ]

@hans-pragt
Copy link

This can be encountered if a preprocessor beforehand has already produced multiple outputs, too.

For example, sourcemaps preprocessing will result in ['foo.js', 'foo.js.map'].

Yep, setting 'devtool' to 'none' fixed this issue for me.

@joseph-jja
Copy link

Same issue in 3.0.5, so staying on 3.0.0. Mac and linux OSes

@nronnei
Copy link

nronnei commented Nov 16, 2018

Confirming that this is still an issue on 3.0.5 running Ubuntu 16.04 and 18.04.

@aburai
Copy link

aburai commented Nov 17, 2018

@MayhemYDG oh damn, i'll try that, cheers.

Update: same results, wtf

> [email protected] test /home/thijs/projects/wavesurfer.js
> karma start karma.conf.js

(node:4394) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead
    at Plugin.<anonymous> (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:109:14)
    at Array.forEach (<anonymous>)
    at Plugin (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:108:16)
    at invoke (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:75:15)
    at Array.instantiate (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:59:20)
    at get (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:48:43)
    at /home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:71:14
    at Array.map (<anonymous>)
    at Array.invoke (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:70:31)
    at Injector.get (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:48:43)
    at instantiatePreprocessor (/home/thijs/projects/wavesurfer.js/node_modules/karma/lib/preprocessor.js:50:20)
    at Array.forEach (<anonymous>)
    at createPreprocessor (/home/thijs/projects/wavesurfer.js/node_modules/karma/lib/preprocessor.js:68:20)
    at Array.invoke (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:75:15)
    at get (/home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:48:43)
    at /home/thijs/projects/wavesurfer.js/node_modules/di/lib/injector.js:71:14
ℹ 「wdm」: wait until bundle finished: noop
ℹ 「wdm」: wait until bundle finished: noop
ℹ 「wdm」: wait until bundle finished: noop
ℹ 「wdm」: wait until bundle finished: noop
06 09 2018 17:25:33.856:ERROR [karma]: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string
    at assertPath (path.js:39:11)
    at Object.join (path.js:1158:7)
    at Plugin.<anonymous> (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:262:68)
    at Plugin.readFile (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:281:5)
    at process._tickCallback (internal/process/next_tick.js:176:11)
06 09 2018 17:25:33.858:ERROR [karma]: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string
    at assertPath (path.js:39:11)
    at Object.join (path.js:1158:7)
    at Plugin.<anonymous> (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:262:68)
    at Plugin.readFile (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:281:5)
    at process._tickCallback (internal/process/next_tick.js:176:11)
06 09 2018 17:25:33.859:ERROR [karma]: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string
    at assertPath (path.js:39:11)
    at Object.join (path.js:1158:7)
    at Plugin.<anonymous> (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:262:68)
    at Plugin.readFile (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:281:5)
    at process._tickCallback (internal/process/next_tick.js:176:11)
06 09 2018 17:25:33.859:ERROR [karma]: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string
    at assertPath (path.js:39:11)
    at Object.join (path.js:1158:7)
    at Plugin.<anonymous> (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:262:68)
    at Plugin.readFile (/home/thijs/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:281:5)
    at process._tickCallback (internal/process/next_tick.js:176:11)
ℹ 「wdm」: 
ℹ 「wdm」: Compiled successfully.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `karma start karma.conf.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

@thijstriemstra hope it helps

Fixed "path" error with
var webpackConfig = require('./build-config/webpack.prod.main.js'); webpackConfig.devtool = 'none';
in karma.conf.js

DeprecationWarning is gone with
"karma-webpack": "^4.0.0-rc.2"

@elliotykim
Copy link

I took another look at the original post. It looks like my issue is separate (but similar) to this one, where instead of receiving an unexpected array (like the OP), it is receiving undefined, which is also an invalid argument for the path.join() method as used in lines 238 and 255.

@npetruzzelli were you able to resolve this? for now I just pinned to version 3.0.0 and it works

@npetruzzelli
Copy link

@elliotykim - I have not been able to explore the issue further nor have I been able to contribute to resolving it. Life has kept me busy with other things. I have not been able to test if updates have resolved the issue.

My work around is exactly the same as you in that I explicitly use:

  • "karma-webpack": "3.0.0", instead of
  • "karma-webpack": "^3.0.0",

@chrisnicola
Copy link

Still seeing this in 3.0.5 and in 4.0.0-rc.6. The test failures are intermittent however for me.

@dsuckau
Copy link

dsuckau commented Apr 10, 2019

Why is this closed? Still having the same issue with 3.0.5. Have to pin hard to 3.0.0 and it works.

@trcarden
Copy link

@michael-ciniawsky should this still stay closed? Seems like people are still coming in with issues.

Likewise seeing intermittent test failures. We are running "karma-webpack": "^4.0.2", adding or removing the dev-tool didn't seem to have an effect.

28 06 2019 23:52:50.773:ERROR [karma-server]: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at validateString (internal/validators.js:125:11)
    at Object.join (path.js:1037:7)
    at Plugin.<anonymous> (/path/to/node_modules/karma-webpack/dist/karma-webpack.js:317:70)
    at Plugin.readFile (/path/to/node_modules/karma-webpack/dist/karma-webpack.js:333:5)
    at /path/to/node_modules/karma-webpack/dist/karma-webpack.js:352:19
    at nextPreprocessor (/path/to/node_modules/karma/lib/preprocessor.js:32:26)
    at /path/to/node_modules/karma/lib/preprocessor.js:121:9
    at module.exports (/path/to/node_modules/isbinaryfile/index.js:29:12)
    at readFileCallback (/path/to/node_modules/karma/lib/preprocessor.js:87:7)

@trcarden
Copy link

I created a new ticket with a possible solution to the problem. See #422 and the "Workaround" section

devDefiWeb added a commit to devDefiWeb/electron-mail-app that referenced this issue May 28, 2022
* by reverting broken "karma-webpack" 3.0.2=>3.0.1, codymikol/karma-webpack#350
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