TransWikia.com

Unexpected token error when using Vue-pdf

Stack Overflow Asked on February 6, 2021

I’m creating an SPA with Laravel and Vue and am trying to use vue-pdf. I’ve successfully integrated several npm packages, but this one is giving me the error:

Uncaught SyntaxError: Unexpected token '<'

When I click on the file (worker.js) in my console, it looks like it’s trying to perform a get request for a regular page on my site instead of grabbing the javascript so my hunch is that webpack isn’t correctly transpiling vue-pdf. My current webpack config is:

const path = require('path')
const fs = require('fs-extra')
const mix = require('laravel-mix')
require('laravel-mix-versionhash')
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')

mix
  .js('resources/js/app.js', 'public/dist/js')
  .sass('resources/sass/app.scss', 'public/dist/css')
  .sass('resources/sass/flowy.scss', 'public/dist/css')

mix.babel([
  'resources/js/helpers/Date.js',
  'resources/js/helpers/LoginRedirect.js'
], 'public/assets/js/combined.js')

  .disableNotifications()

if (mix.inProduction()) {
  mix
    // .extract() 
    // .version() 
    .versionHash()
} else {
  mix.sourceMaps()
}

mix.webpackConfig({
  plugins: [
    // new BundleAnalyzerPlugin()
  ],
  resolve: {
    extensions: ['.js', '.json', '.vue'],
    alias: {
      '~': path.join(__dirname, './resources/js')
    }
  },
  output: {
    chunkFilename: 'dist/js/[chunkhash].js',
    path: mix.config.hmr ? '/' : path.resolve(__dirname, './public/build')
  }
})

mix.then(() => {
  if (!mix.config.hmr) {
    process.nextTick(() => publishAseets())
  }
})

function publishAseets () {
  const publicDir = path.resolve(__dirname, './public')

  if (mix.inProduction()) {
    fs.removeSync(path.join(publicDir, 'dist'))
  }

  fs.copySync(path.join(publicDir, 'build', 'dist'), path.join(publicDir, 'dist'))
  fs.removeSync(path.join(publicDir, 'build'))
}

Any help would be appreciated.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP