Ask questionsunclear / difficult to import uuidv4

  1. install normal svelte template
  2. npm install uuid --save
  3. import uuidv4 from "uuid/v4"
  4. make a function which invokes uuidv4()
  5. chrome localhost:5000
  6. uuidv4 does not work

(!) Unresolved dependencies crypto (imported by node_modules/uuid/lib/rng.js, commonjs-external-crypto) (!) Missing global variable name Use output.globals to specify browser global variable names corresponding to external modules crypto (guessing 'crypto')

How can we clarify how to make svelte handle this dependency?

No luck with results on google. Potential opportunity: improve docs re: dependencies


Answer questions EmilTholin

Hi @bionicles!

uuid/v4 uses a Node build by default that doesn't work in the browser. You can set the browser option of the rollup-plugin-node-resolve plugin to true in order for Rollup to look for the browser field in dependencies' package.json instead and use that build if it exists.

  browser: true

Related questions

Javascript Interpolation in Styles via CSS Variables? hot 2
Svelte applications fail to load in IE 11. Similar loading issue with the main site hot 1
Uncaught TypeError: y.fragment.l is not a function hot 1
Increase elements when using a combination of await block and transition hot 1
Svelte applications fail to load in IE 11. Similar loading issue with the main site hot 1
Change body class via <svelte:body /> hot 1
Site: Svelte Cookbook/ Examples hot 1
Missing dependencies in svelte/compiler type definitions hot 1
Multiple components in one file - svelte hot 1
onMount Error: Function called outside component initialization hot 1
A way to see if slot prop is present hot 1
slot inside #if inside #each : TypeError cannot read property 'd' of null hot 1
Use <script type="application/ld+json"> in <svelte:head> hot 1
Error: 'default' is not exported when using babel + moment hot 1
Outros undefined when transitioning to another page hot 1
Github User Rank List