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

window is not defined in worker file #97

Open
a47ae opened this issue Jun 21, 2018 · 14 comments
Open

window is not defined in worker file #97

a47ae opened this issue Jun 21, 2018 · 14 comments

Comments

@a47ae
Copy link

a47ae commented Jun 21, 2018

This is not really an issue with vue-pdf but I ran into this recently and tought it may be worth sharing.
When using vue-pdf with Webpack 4 (e.g. a project created by vue-cli v3) the dev build with hot reloading gave the following error message:

window is not defined in worker[hash].js

and vue-pdf did not display anything.

This only occurs on development builds with hot reloading, on production it is fine.
After investigating I found the following issue to be the reason why this happens: webpack/webpack#6642

Until this is fixed in webpack the following workaround did work for me.
In the Webpack config set the following option:

 output: {
  globalObject: 'this'
}
@FossPrime
Copy link
Contributor

FossPrime commented Jul 3, 2018

with vue-cli v3 there is none, and vue.config.js doesn't have an output config.. but it does have configureWebpack...

// vue.config.js
module.exports = {
  css: {
    loaderOptions: {
      // pass options to sass-loader
      sass: {
        // @/ is an alias to src/
        // so this assumes you have a file named `src/variables.scss`
        data: `@import "@/styles/_variables.scss"; @import "@/styles/_mixins.scss";`
      }
    }
  },
  configureWebpack: {
    output: {
      globalObject: 'this' // `typeof self !== 'undefined' ? self : this`'' -- not working
    }
  }
}

@kartsims
Copy link

💯 @a47ae @rayfoss you guys are heroes 🥇

@nothingismagick
Copy link

If you end up here via the Quasar framework, you can use chainWebpack in your quasar.conf.js:

    build: {
      chainWebpack(chain) {
        chain.output.set('globalObject', 'this')

@coreycoburn
Copy link

In Nuxt, you can get this to work in nuxt.config.js:

extend(config, ctx) {
  config.output.globalObject = 'this'
}

@frederic117

This comment has been minimized.

@coreycoburn
Copy link

@frederic117

Make sure you also add ssr: false in your nuxt.config.js file if you are using Nuxt in universal mode.

plugins: [
  { src: '@/plugins/pdf', ssr: false },
]

https://nuxtjs.org/guide/plugins/#client-side-only

@frederic117

This comment has been minimized.

@imaxing

This comment has been minimized.

@frederic117
Copy link

Still waiting

@FranckFreiburger

This comment has been minimized.

@HealerNguyen
Copy link

HealerNguyen commented Apr 17, 2019

In Nuxt, you can get this to work in nuxt.config.js:

extend(config, ctx) {
  config.output.globalObject = 'this'
}

this saved me :D , thank you @coreycoburn

@io-ma
Copy link

io-ma commented Apr 25, 2019

Not working for me. I am not able to load the PDF no matter what I do (place it in the /static dir or on a server). Using webpack 4 too :-(
Tried the 'this' trick, but it's still blank...
Screenshot from 2019-04-25 13-41-30

@zardilior
Copy link

Working solution on this link #148

@mryassera
Copy link

Solve this issue for nuxt.js
👇
#148 (comment)

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