I'd like to provide a runtime assert
to all code in a Sapper application I'm making.
Edited:
Bringing the assert
module works for server
builds, but not for client
builds, showing either of these 500 error messages in the browser:
import { strict as sa } from 'assert';
With this, client build shows a warning:
'assert' is imported by src/assert.js, but could not be resolved – treating it as an external dependency
const sa = require("assert").strict;
With this, client build passes. :/
My rollup.config.js
and package.json
.
Disclaimer: I am new to Svelte and Sapper and have no idea what should be done, here. My goal is not only to get it to work, but also understand what went wrong (i.e. learn about the Sapper/Svelte packaging mechanisms).
Original description:
This should be simple. Define a global high up (the app can import
or require
the assert
and place it available). In practise, I'm still confused.
I've thought about setting window.assert
directly (a bit harsh?) and passing the value as a parameter to those components actually needing it (but parameter passing looks difficult).
This is a case of dependency injection in the way that I'd like there to be an assert
and the lower code doesn't care, which flavour.
Note: console.assert
won't do because it only prints out the message. Chrome has an option for making it break. I may consider that.