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

Thread-loader with non-serializable types #5723

Closed
RobbinBaauw opened this issue Jul 28, 2020 · 3 comments
Closed

Thread-loader with non-serializable types #5723

RobbinBaauw opened this issue Jul 28, 2020 · 3 comments

Comments

@RobbinBaauw
Copy link
Contributor

RobbinBaauw commented Jul 28, 2020

Version

4.5.0

Reproduction link

https://github.com/RobbinBaauw/vue-cli-thread-repro

Environment info

 System:
    OS: Linux 5.7 Pop!_OS 20.04 LTS
    CPU: (8) x64 Intel(R) Core(TM) i7-6700K CPU @ 4.00GHz
  Binaries:
    Node: 14.5.0 - /opt/node/bin/node
    Yarn: 1.22.4 - /opt/node/bin/yarn
    npm: 6.14.5 - /opt/node/bin/npm
  Browsers:
    Chrome: 83.0.4103.116
    Firefox: 78.0.2
  npmPackages:
    @vue/cli: ^4.5.0 => 4.5.0 
    @vue/cli-shared-utils:  4.5.0 
    @vue/cli-ui:  4.5.0 
    @vue/cli-ui-addon-webpack:  4.5.0 
    @vue/cli-ui-addon-widgets:  4.5.0 
    @vue/compiler-core:  3.0.0-rc.4 
    @vue/compiler-dom:  3.0.0-rc.4 
    @vue/compiler-sfc:  3.0.0-rc.4 
    @vue/compiler-ssr:  3.0.0-rc.4 
    @vue/reactivity:  3.0.0-rc.4 
    @vue/runtime-core:  3.0.0-rc.4 
    @vue/runtime-dom:  3.0.0-rc.4 
    @vue/shared:  3.0.0-rc.4 
    typescript:  3.9.7 
    vue:  3.0.0-rc.4 (2.6.11)
    vue-cli-plugin-apollo:  0.21.3 
    vue-codemod:  0.0.4 
  npmGlobalPackages:
    @vue/cli: 4.5.0

Steps to reproduce

Note that I made 2 changes w.r.t. a generated project (RobbinBaauw/vue-cli-thread-repro@7295f13):

  1. Added invalid typescript in main.ts
  2. Added vue.config.js and changed ts-loader with an errorFormatter. Set parallel to true.

Now build. You'll get an error:

 error  in ./src/main.ts

Module build failed (from ./node_modules/thread-loader/dist/cjs.js):
Thread Loader (Worker 0)
Cannot read property 'hooks' of undefined
...

If you change parallel to false, it'll give the custom typescript error. This is expected behavior.

What is expected?

Both parallel and non-parallel give this typescript custom error

What is actually happening?

If thread-loader is used (so for compiling Typescript or by using Babel), the config is passed to the threads in buffers (strings). If you use non-serializable objects in your vue.config.js (such as functions), these objects are removed when serializing to this string, and thus you get these "undefined" errors when using thread-loader (see webpack-contrib/thread-loader#89 (comment)).


I ran into this "bug" when providing a custom renderer in Vue. This repro however shows that any reference type (such as functions) doesn't work. I don't know how to solve this properly, but at least providing a clear heads up in the docs (for example on https://cli.vuejs.org/guide/webpack.html) would be nice.

@RobbinBaauw RobbinBaauw changed the title Thread-loader with references Thread-loader with non-serializable types Jul 29, 2020
sodatea added a commit to vuejs/vue-loader that referenced this issue Aug 10, 2020
So that all the options are serializable and can be used with
thread-loader.

Fixes #1705
Fixes vuejs/vue-cli#5723
@sodatea
Copy link
Member

sodatea commented Aug 11, 2020

Fixed in vue-loader v16.0.0-beta.5

@sodatea sodatea closed this as completed Aug 11, 2020
@RobbinBaauw
Copy link
Contributor Author

This doesn't fix the issues for other loaders. I think a warning in the docs at the parallel option would prevent some people from having to debug this (as many will probably be unknown with the fact that thread-loader is used and that it has this downside).

@sodatea
Copy link
Member

sodatea commented Aug 11, 2020

Makes sense. PR's welcome.

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

2 participants