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

Outputs can have multiple assets #355

Closed
43081j opened this issue Sep 7, 2018 · 16 comments
Closed

Outputs can have multiple assets #355

43081j opened this issue Sep 7, 2018 · 16 comments

Comments

@43081j
Copy link

43081j commented Sep 7, 2018

Similar to #350.

If an input has multiple output assets, an error will be thrown as the path will be an array rather than string.

This is because assetsByChunkName entries can be arrays:

https://webpack.js.org/api/stats/

But in karma webpack, we assume it is always a string:

https://github.com/webpack-contrib/karma-webpack/blob/d42c5418d93508c94d40031c42ca7107dd6f1a73/src/karma-webpack.js#L174

Using the source maps loader will cause this error as one js file will produce a map and a js asset

@michael-ciniawsky
Copy link
Contributor

michael-ciniawsky commented Sep 7, 2018

I see, would you mind trying to send PR to fix this? Checking for an {Array} and setting each item (entry) individually should be sufficient

@michael-ciniawsky
Copy link
Contributor

cc @rynclark :)

@ryanclark
Copy link
Collaborator

ryanclark commented Sep 7, 2018 via email

@michael-ciniawsky
Copy link
Contributor

External sourcemaps currently don't seem work with karma-webpack according to the issue tracker, maybe we can fix that now aswell 🤔, but please let us focus on fixing the Path must be a string... issue first :) Should make it easier if we can ignore the .map file for now. Hopefully assetsByChunkName is deterministic 🙃

@GreenGremlin
Copy link

This also happens if a js file imports a css file. Possibly, only when using the extract-text-webpack-plugin.

@thijstriemstra
Copy link

fyi, also seeing this with 4.0.0 rc2:

08 09 2018 02:13:38.035:ERROR [karma]: TypeError: Path must be a string. Received [ 'spec/wavesurfer.spec.js', 'spec/wavesurfer.spec.js.map' ]
    at assertPath (path.js:28:11)
    at Object.join (path.js:1236:7)
    at Plugin.<anonymous> (/Users/foo/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:286:70)
    at Plugin.readFile (/Users/foo/projects/wavesurfer.js/node_modules/karma-webpack/lib/karma-webpack.js:305:5)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

@Bobsans
Copy link

Bobsans commented Sep 10, 2018

+1
karma-webpack: ^4.0.0-rc.2

I use vue and mini-css-extract-plugin

10 09 2018 11:47:59.087:ERROR [karma]: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
    at assertPath (path.js:39:11)
    at Object.join (path.js:434:7)
    at Plugin.<anonymous> (D:\Python\proj\node_modules\karma-webpack\lib\karma-webpack.js:286:70)
    at Plugin.readFile (D:\Python\proj\node_modules\karma-webpack\lib\karma-webpack.js:305:5)
    at process._tickCallback (internal/process/next_tick.js:61:11)

and this.outputs is:

{
	"../test/components/Fa.spec.js":"..\\test\\components\\Fa.spec.f35f.js",
	"../test/components/Loader.spec.js":[
		"..\\test\\components\\Loader.spec.css",
		"..\\test\\components\\Loader.spec.f35f.js"
	],
	"../test/components/Url.spec.js":"..\\test\\components\\Url.spec.f35f.js"
}

@alabbas-ali
Copy link
Contributor

Please check PR #357

@43081j
Copy link
Author

43081j commented Sep 26, 2018

Some regression or something happened with this...

With 3.0.5, test runs now do complete but some craziness goes on with multiple outputs.

If you have the sourcemaps loader enabled, for example, the resulting JS has two different sourcemaps so they fail to load correctly in chrome. Installing 3.0.0 makes it work again, so we've definitely introduced a bug somewhere.

foo;
// sourceMap;url=...
// sourceMap:url=...

This is the kind of thing we end up with.

@dulcetti
Copy link

dulcetti commented Oct 5, 2018

Here with version 4.0.0-rc.2 I receive the error:

05 10 2018 11:21:11.759:ERROR [karma]: TypeError: Path must be a string. Received [ 'assets/css/app.style.6c4578761796562b94a9.min.css',
  'assets/css/app.style.6c4578761796562b94a9.min.css.map' ]

If I downgrade to 3.0.5, I recevei the message (node:14254) DeprecationWarning: Tapable.plugin is deprecated. Use new API on .hooks instead because version 4 of Webpack.

@didi0613
Copy link

The same thing happened here with version 4.0.0-rc.2
Error:

19 11 2018 14:16:25.525:ERROR [karma-server]: TypeError: Path must be a string. Received [ 'node_modules/electrode-archetype-react-component-dev/config/karma/entry.style.0ca30711e2d0162e57a8.css',
  'node_modules/electrode-archetype-react-component-dev/config/karma/entry.style.0ca30711e2d0162e57a8.css.map',
  'node_modules/electrode-archetype-react-component-dev/config/karma/entry.style.0ca30711e2d0162e57a8.css.map' ]

@ryanclark
Copy link
Collaborator

Does 4.0.0-rc.3 fix this for you?

@thijstriemstra
Copy link

No, I'm still seeing this #355 (comment) with rc3.

@matthieu-foucault
Copy link
Collaborator

@thijstriemstra : Can you use webpack-stats-plugin to output the assetsByChunkName object that triggers this error?

This issue seems only partially fixed

@thijstriemstra
Copy link

@matthieu-foucault resulting stats.json:

{
  "assetsByChunkName": {
    "videojs.record": [
      "css/videojs.record.min.css",
      "videojs.record.min.js",
      "videojs.record.min.js.map"
    ]
  }
}

@matthieu-foucault
Copy link
Collaborator

@thijstriemstra: I finally found some time to look into this, using your project (collab-project/videojs-record) to debug the issue.
What you are experiencing is a different issue, due to the fact that your webpack output.filename is a static name, which is a problem since you have more that a single entry point when testing with karma (each test file is an entry point), and they all end up being emmited to the same output.
I am still investigating as to why this now fails when it seems that it worked with beta.0, but that's a separate issue.
In the meantime, it seems that using [name].js as output.filename works around the issue.

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

10 participants