Skip to content

Plugin crushes the build in Preact application #17

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

Open
alfesen opened this issue Feb 6, 2024 · 1 comment
Open

Plugin crushes the build in Preact application #17

alfesen opened this issue Feb 6, 2024 · 1 comment

Comments

@alfesen
Copy link

alfesen commented Feb 6, 2024

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')
    }
  }
})

@DelliriumX
Copy link

Sorry for necro-ing but having the same issues.

I've tracked it down to being the problem with "all" as it injects all system variables, and these happen to be formatted in such a way that they are not a valid identifier. You could try exposing individual variables with the array syntax, but this, at least for me, defeats the purpose of this plugin as we can do this with define just as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants