I’m trying to use the functions in lib-r-math.js in a vite app.
I have installed lib-r-math.js in the project with:
npm i lib-r-math.js
and I have the following code for demo app:
<script setup>
import { ref } from 'vue'
import { qnorm } from 'lib-r-math.js';
const num = ref(.5);
function getR(x){
return qnorm(x)
}
</script>
<template>
<main>
<textarea v-model='num'></textarea>
<textarea>{{getR(num)}}</textarea>
</main>
</template>
When I run the demo app with npm run dev
, I get the following in my browser console:
Module "crypto" has been externalized for browser compatibility. Cannot access "crypto.randomBytes" in client code. See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
and
Uncaught TypeError: import_crypto.randomBytes is not a function
seed seed.mjs:3
MersenneTwister index.mjs:15
<anonymous> global-rng.mjs:157
I have read the doc suggested but I am no closer to understanding how to include the library. What is the correct way of including lib-r-math.js
so that the code functions?