storybook: [Bug]: Clean Vite + Svelte Install with Storybook leads to `ReferenceError: process is not defined`

Describe the bug

Hey all,

Just setting up a new storybook project, and ran it as documented in https://storybook.js.org/blog/storybook-for-vite/. Running storybook then triggers the client error:

ReferenceError: process is not defined (in memoizerific.js:4:31)

Digging a bit deeper, its specifically referring toprocess.env.FORCE_SIMILAR_INSTEAD_OF_MAP.

To Reproduce

  1. Run pnpm create vite@latest, and when prompted:
  • provide a project name
  • select Svelte
  • select Typescript
  1. cd into-your-project
  2. pnpm install
  3. Run pnpx sb init --builder @storybook/builder-vite
  4. Open [localhost](http://localhost:6006/) in your browser
  5. See Error: process not defined
  6. Check console.

System

System:
    OS: macOS 13.0.1
    CPU: (8) arm64 Apple M2
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 20.2.0 - /opt/homebrew/bin/node
    npm: 9.6.6 - /opt/homebrew/bin/npm
    pnpm: 8.6.1 - /opt/homebrew/bin/pnpm <----- active
  Browsers:
    Chrome: 119.0.6045.199
    Safari: 16.1
  npmPackages:
    @storybook/addon-essentials: ^7.6.4 => 7.6.4
    @storybook/addon-interactions: ^7.6.4 => 7.6.4
    @storybook/addon-links: ^7.6.4 => 7.6.4
    @storybook/blocks: ^7.6.4 => 7.6.4
    @storybook/svelte: ^7.6.4 => 7.6.4
    @storybook/svelte-vite: ^7.6.4 => 7.6.4
    @storybook/test: ^7.6.4 => 7.6.4
    storybook: ^7.6.4 => 7.6.4

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (8 by maintainers)

Most upvoted comments

I found that the main problem is with Vite ^5.0.0. Had to do a pretty bad workaround to make it work and I don’t really know how it will impact my project.

the workaround is going to the vite.config.js file and then adding define: { "process.env" : {} }, and the file will look like this:


import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';

export default defineConfig({
	plugins: [sveltekit()],
	test: {
		include: ['src/**/*.{test,spec}.{js,ts}']
	},
	define: {
		"process.env": {}
	}
});

This looks pretty bad for me, but made it work.