Skip to content

[Bug]: import.meta.env undefined since beta6 #3029

@abenhamdine

Description

@abenhamdine

Version

System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Memory: 1.77 GB / 15.36 GB
  Browsers:
    Edge: Chromium (123.0.2420.65)
  npmPackages:
    @rsbuild/core: 1.0.1-beta.6 => 1.0.1-beta.6
    @rsbuild/plugin-eslint: 1.0.0 => 1.0.0
    @rsbuild/plugin-react: 1.0.1-beta.6 => 1.0.1-beta.6
    @rsbuild/plugin-type-check: 1.0.1-beta.6 => 1.0.1-beta.6

Details

Since beta6, our app breaks because import.meta.env is no more accessible in the code at runtime :

The error occurs at the following code :

let isDialogOpened: boolean = false

// line 43 here after
if (import.meta.env.PUBLIC_SENTRY_DSN) {
	Sentry.init({
		dsn: import.meta.env.PUBLIC_SENTRY_DSN,
		environment: import.meta.env.PUBLIC_MODE,
// ...etc
App.tsx:43 Uncaught TypeError: Cannot read properties of undefined (reading 'PUBLIC_SENTRY_DSN')
    at ./src/App.tsx (App.tsx:43:1)
    at __webpack_require__ (validators.ts:82:1)
    at fn (validators.ts:82:1)
    at ./src/index.tsx (getInfosForValidationAbsence.ts:108:1)
    at __webpack_require__ (validators.ts:82:1)
    at validators.ts:82:1
    at __webpack_require__.O (validators.ts:82:1)
    at validators.ts:82:1
    at validators.ts:82:1

if we revert back to beta 5, everything works fine again.

Reproduce link

Sorry I will try to post a reproduction later

Reproduce Steps

yarn run dev

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions