Vue-cli: [worker-loader] window is not defined

Created on 19 Aug 2018  路  5Comments  路  Source: vuejs/vue-cli

Version

3.0.1

Reproduction link

https://github.com/screendriver/vue-cli-worker-loader-bug

Node and OS info

Node 10.9.0 / yarn 1.9.4 / macOS high sierra

Steps to reproduce

Just do a yarn serve and open http://localhost:8080 in your browser. You can see the error immediately.

What is expected?

Should not throw Uncaught ReferenceError: window is not defined.

What is actually happening?

Throws the error and doesn't work.

bug

Most helpful comment

this work for me, add to vue.config.js
configureWebpack: { output: { globalObject: 'this', }, },

All 5 comments

I ran into similar issues in a worker-loader + webpack-worker-wrapper setup. You can work around it by adding this to your vue.config.js :

module.exports = {
  chainWebpack: config => {
    config.output.globalObject('this')
  }
}

... and doing something like this in your worker.js files :

import workerGlobals from './workerGlobals.js'

and in workerGlobals.js

//Comment the lines you don't need.
global.process = process
window = undefined

this work for me, add to vue.config.js
configureWebpack: { output: { globalObject: 'this', }, },

Oh it works. Great!
Maybe it would be a good idea to include that webpack loader directly into vue cli? 馃

Take a look to #2286!

@Kocal that "just" fixes the issue where I have to add configureWebpack: { output: { globalObject: 'this', }, } manually to my project but not that worker-loader will be add by vue-cli automatically (or via propmt) 馃槈

Was this page helpful?
0 / 5 - 0 ratings

Related issues

evelynhathaway picture evelynhathaway  路  35Comments

xrei picture xrei  路  40Comments

italomaia picture italomaia  路  88Comments

yyx990803 picture yyx990803  路  80Comments

dimavolo picture dimavolo  路  75Comments