crabbly / Print.js

A tiny javascript library to help printing from the web.
MIT License
4.28k stars 672 forks source link

window is not defined in SapperJs #400

Closed TeddyPerkins closed 4 years ago

TeddyPerkins commented 4 years ago

SapperJs gives 'window is not defined' error with Print.js; It also gives 'use of eval is strongly discouraged' but as long as it works I dont mind; Here is the github repo: Sapperprint

This is a boilerplate sapper with print-js installed; I have previously tried in simple html + js in codepen and VSCode and the worked; I installed print-js via npm install;

If anyone could just send the corrected CODE, it would be highly appreciated!

TeddyPerkins commented 4 years ago

User kapilpipaliya solved it,

import { onMount } from 'svelte'
    let printJS 
    onMount(async ()=>{
        const p = await import('print-js')
        printJS = p.default
        console.log(printJS)
    })

Anyone can look at repos commit to know more, I am closing the issue....