Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve the error message of expand #11141

Merged
merged 3 commits into from Dec 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 15 additions & 3 deletions packages/vite/src/node/env.ts
Expand Up @@ -35,15 +35,27 @@ export function loadEnv(
})
)

// let environment variables use each other
const expandParsed = expand({
const expandOptions = {
parsed: {
...(process.env as any),
...parsed
},
// prevent process.env mutation
ignoreProcessEnv: true
}).parsed!
}

let expandParsed: NonNullable<ReturnType<typeof expand>['parsed']>
try {
// let environment variables use each other
expandParsed = expand(expandOptions).parsed!
} catch (e) {
if (e.message.includes('split')) {
Dunqing marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(
'dotenv-expand failed to expand env vars. Maybe you need to escape `$`?'
)
}
throw e
}

Object.keys(parsed).forEach((key) => {
parsed[key] = expandParsed[key]
Expand Down