Registry / web-framework / svelte-environment-variables

svelte-environment-variables

JSON →
library1.0.4jsnpmunverified

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.

npm install svelte-environment-variables
INSTALL
IMPORT
SIG · SVELTE-ENVIRONMENT
S
svelte-environment-variables
web-frameworkjavascriptv1.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

includeEnv
import includeEnv from 'svelte-environment-variables'
const includeEnv = require('svelte-environment-variables')
Package does not ship TypeScript types; you may need to declare module or use @ts-ignore. Default export only.

Configures Rollup to replace environment variables prefixed with SVELTE_APP_ at build time.

// install: npm install svelte-environment-variables @rollup/plugin-replace // .env file: SVELTE_APP_API_URL="https://api.example.com" // rollup.config.js import replace from '@rollup/plugin-replace'; import includeEnv from 'svelte-environment-variables'; export default { client: { plugins: [ replace({ ...includeEnv({ filterPrefix: 'SVELTE_APP_', targetPrefix: 'process.env.' }), preventAssignment: true, }), ], }, }; // In Svelte component: console.log(process.env.SVELTE_APP_API_URL); // outputs 'https://api.example.com'
Debug
Known issues
gotchaOnly environment variables with the configured prefix are replaced; others remain as literal 'process.env.X' in the bundle.
fix
Ensure all client-side env vars use the prefix (default 'SVELTE_APP_').
affects: >=1.0.0
gotchaIf using with env-cmd, the .env file must be loaded before the build script; otherwise variables may not be present.
fix
Wrap build script with env-cmd: 'env-cmd npm run dev'
affects: >=1.0.0
gotchaWith @rollup/plugin-replace v3+, you must set 'preventAssignment: true' to avoid deprecation warnings.
fix
Add preventAssignment: true to replace options.
affects: >=1.0.0
deprecatedPackage has not been updated since 2020; considered in maintenance mode. No plans to support TypeScript, Vite, or SvelteKit.
fix
Migrate to SvelteKit's $env module or Vite's import.meta.env for newer projects.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'svelte-environment-variables'
Package not installed or not in node_modules.
fix
Run 'npm install svelte-environment-variables'
Uncaught ReferenceError: process is not defined
process.env.X not replaced; likely missing replace plugin or configuration.
fix
Ensure @rollup/plugin-replace is configured with ...includeEnv() and that the variable has the correct prefix.
TypeError: includeEnv is not a function
Using CommonJS require but package default export is not a function in that context.
fix
Use 'const includeEnv = require('svelte-environment-variables').default' or switch to ES6 import.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
svelte-environment-variables — npm install svelte-environment-variables · libregistry