{"id":27433,"library":"svelte-environment-variables","title":"svelte-environment-variables","description":"A tiny helper (v1.0.4, no recent updates) for Svelte/Sapper apps that replaces environment variables with a configurable prefix (default SVELTE_APP_) at build time using Rollup's @rollup/plugin-replace or Webpack's DefinePlugin. Unlike Vite's built-in import.meta.env or dotenv, this package is Rollup/Webpack-only and designed specifically for Svelte/Sapper. No TypeScript types are included. Last published in 2020, it is effectively in maintenance mode.","status":"maintenance","version":"1.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/saikatdas0790/svelte-environment-variables","tags":["javascript","environment","variables","svelte","sapper","rollup","webpack"],"install":[{"cmd":"npm install svelte-environment-variables","lang":"bash","label":"npm"},{"cmd":"yarn add svelte-environment-variables","lang":"bash","label":"yarn"},{"cmd":"pnpm add svelte-environment-variables","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package does not ship TypeScript types; you may need to declare module or use @ts-ignore. Default export only.","wrong":"const includeEnv = require('svelte-environment-variables')","symbol":"includeEnv","correct":"import includeEnv from 'svelte-environment-variables'"}],"quickstart":{"code":"// install: npm install svelte-environment-variables @rollup/plugin-replace\n// .env file: SVELTE_APP_API_URL=\"https://api.example.com\"\n// rollup.config.js\nimport replace from '@rollup/plugin-replace';\nimport includeEnv from 'svelte-environment-variables';\n\nexport default {\n  client: {\n    plugins: [\n      replace({\n        ...includeEnv({ filterPrefix: 'SVELTE_APP_', targetPrefix: 'process.env.' }),\n        preventAssignment: true,\n      }),\n    ],\n  },\n};\n\n// In Svelte component:\nconsole.log(process.env.SVELTE_APP_API_URL); // outputs 'https://api.example.com'","lang":"javascript","description":"Configures Rollup to replace environment variables prefixed with SVELTE_APP_ at build time."},"warnings":[{"fix":"Ensure all client-side env vars use the prefix (default 'SVELTE_APP_').","message":"Only environment variables with the configured prefix are replaced; others remain as literal 'process.env.X' in the bundle.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Wrap build script with env-cmd: 'env-cmd npm run dev'","message":"If using with env-cmd, the .env file must be loaded before the build script; otherwise variables may not be present.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Add preventAssignment: true to replace options.","message":"With @rollup/plugin-replace v3+, you must set 'preventAssignment: true' to avoid deprecation warnings.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Migrate to SvelteKit's $env module or Vite's import.meta.env for newer projects.","message":"Package has not been updated since 2020; considered in maintenance mode. No plans to support TypeScript, Vite, or SvelteKit.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'npm install svelte-environment-variables'","cause":"Package not installed or not in node_modules.","error":"Error: Cannot find module 'svelte-environment-variables'"},{"fix":"Ensure @rollup/plugin-replace is configured with ...includeEnv() and that the variable has the correct prefix.","cause":"process.env.X not replaced; likely missing replace plugin or configuration.","error":"Uncaught ReferenceError: process is not defined"},{"fix":"Use 'const includeEnv = require('svelte-environment-variables').default' or switch to ES6 import.","cause":"Using CommonJS require but package default export is not a function in that context.","error":"TypeError: includeEnv is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}