I have to move a component from svelte-sapper to sapper. The component uses uuid in this way
import { v4 as uuidv4} from uuid
I installed also crypto. When i use that component on the console browser i have this error
rng.js:4 Uncaught TypeError: crypto.randomFillSync is not a function
and on the console:
bundles src/index.js → dist/index.mjs, dist/index.js, public/build/bundle.js...
(!) Missing global variable names
Use output.globals to specify browser global variable names corresponding to external modules
crypto (guessing 'crypto')
crypto (guessing 'crypto')
I already installed crypto with npm, the function is on bundle.js
const rnds8 = new Uint8Array(16); function rng() { return crypto.randomFillSync(rnds8); }
I saw that i need to use inside rollup.config.js, inside plugin element
resolve({ browser: true }),
But it did not work. Any suggestions?
here there is my rollup
import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import pkg from './package.json';
const production = !process.env.ROLLUP_WATCH;
const name = pkg.name
.replace(/^(@\S+\/)?(svelte-)?(\S+)/, '$3')
.replace(/^\w/, m => m.toUpperCase())
.replace(/-\w/g, m => m[1].toUpperCase());
export default {
input: 'src/index.js',
output: [
{ file: pkg.module, 'format': 'es' },
{ file: pkg.main, 'format': 'umd', name },
{
sourcemap: true,
format: 'iife',
name: 'app',
file: 'public/build/bundle.js'
}
],
plugins: [
svelte({
// enable run-time checks when not in production
dev: !production,
// we'll extract any component CSS out into
// a separate file - better for performance
css: css => {
css.write('public/build/bundle.css');
}
}),
resolve({
browser: true
}),
commonjs(),
// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve()
]
};
function serve() {
let started = false;
return {
writeBundle() {
if (!started) {
started = true;
require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
stdio: ['ignore', 'inherit', 'inherit'],
shell: true
});
}
}
};
}