vite-plugin-environment
vite-plugin-environment copied to clipboard
Plugin crushes the build in Preact application
process.env variables work perfectly well during development, but every attempt to build the app results in a bunch of errors.
[commonjs--resolver] Transform failed with 2 errors:
error: The define key "process.env.ProgramFiles(x86)" contains invalid identifier "ProgramFiles(x86)"
error: The define key "process.env.CommonProgramFiles(x86)" contains invalid identifier "CommonProgramFiles(x86)"
error during build:
Error: Transform failed with 2 errors:
error: The define key "process.env.ProgramFiles(x86)" contains invalid identifier "ProgramFiles(x86)"
error: The define key "process.env.CommonProgramFiles(x86)" contains invalid identifier "CommonProgramFiles(x86)"
at failureErrorWithLog (*path*\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:1651:15)
at *path*\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:849:29
at responseCallbacks.<computed> (*path*\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:704:9)
at handleIncomingPacket (*path*\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:764:9)
at Socket.readFromStdout (*path*\node_modules\.pnpm\[email protected]\node_modules\esbuild\lib\main.js:680:7)
at Socket.emit (node:events:514:28)
at addChunk (node:internal/streams/readable:545:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:495:3)
at Readable.push (node:internal/streams/readable:375:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
ELIFECYCLE Command failed with exit code 1.
My initial guess was that it's pnpm's fault, but it resulted the same with npm. Only the removal of EnvironmentPlugin solves the build problem.
import { defineConfig } from 'vite'
import preact from '@preact/preset-vite'
import { resolve } from 'path'
import EnvironmentPlugin from 'vite-plugin-environment'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [preact(), EnvironmentPlugin('all')],
resolve: {
alias: {
components: resolve(__dirname, './src/components'),
hooks: resolve(__dirname, './src/hooks')
}
}
})