I have a Svelte based application which works as predicted on localhost. However when I try to deploy to Netlify, the build fails.
I have the following lines in rollup.config.js
import { config } from 'dotenv';
import replace from '@rollup/plugin-replace';
const configToReplace = {};
for (const [key, v] of Object.entries(config().parsed)) {
configToReplace[`process.env.${key}`] = `'${v}'`;
}
The error occurs on the line
for (const [key, v] of Object.entries(config().parsed)) {
and the error messqge is
$ npm run build
8:16:55 AM: Creating deploy upload records
8:16:55 AM: > svelte-app@1.0.0 build
8:16:55 AM: > rollup -c
8:16:55 AM: [!] TypeError: Cannot convert undefined or null to object
8:16:55 AM: TypeError: Cannot convert undefined or null to object
8:16:55 AM: at Function.entries ()
8:16:56 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
8:16:55 AM: at Object. (/opt/build/repo/rollup.config.js:25:31)
8:16:55 AM: at Module._compile (node:internal/modules/cjs/loader:1126:14)
8:16:55 AM: at Object.require.extensions. [as .js] (/opt/build/repo/node_modules/rollup/dist/shared/loadConfigFile.js:621:20)
8:16:55 AM: at Module.load (node:internal/modules/cjs/loader:1004:32)
8:16:55 AM: at Function.Module._load (node:internal/modules/cjs/loader:839:12)
8:16:55 AM: at Module.require (node:internal/modules/cjs/loader:1028:19)
8:16:55 AM: at require (node:internal/modules/cjs/helpers:102:18)
8:16:55 AM: at loadConfigFromBundledFile (/opt/build/repo/node_modules/rollup/dist/shared/loadConfigFile.js:631:42)
8:16:55 AM: at getDefaultFromTranspiledConfigFile (/opt/build/repo/node_modules/rollup/dist/shared/loadConfigFile.js:613:12)
8:16:55 AM:
8:16:55 AM: ────────────────────────────────────────────────────────────────
8:16:55 AM: “build.command” failed
8:16:55 AM: ────────────────────────────────────────────────────────────────
What do I need to do?