sveltejs/template

ReferenceError: Can't find variable: process

etclub opened this issue · 5 comments

Here are the steps to reproduce it:

  1. install nanoid
  2. modify main.js
import { nanoid } from 'nanoid'
import App from './App.svelte';

const app = new App({
	target: document.body,
	props: {
		name: nanoid()
	}
});

export default app;

If nanoid is written to require Node APIs then you won't be able to use it as-is in a browser. process is a variable that exists in Node and not on browsers.

GitHub issues aren't the right place for support questions like this. Please ask on StackOverflow or in our Discord chat room.

@etclub it's worth noting that nanoid isn't particularly good anyway, and yes, it doesn't run in the browser. Try https://github.com/lukeed/uid instead.

process.env.NODE_ENV is a convention which is usually statically replaced with 'production' or 'development' string. Many browser modules uses it. Webpack replaces it out of the box.

ai commented

To use Nano ID in Rollup you need to add @rollup/plugin-replace

https://github.com/ai/nanoid#rollup