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

Uncaught ReferenceError: __DEFINES__ is not defined at env.ts:17:17 #14314

Closed
7 tasks done
Bersaelor opened this issue Sep 6, 2023 · 5 comments
Closed
7 tasks done

Uncaught ReferenceError: __DEFINES__ is not defined at env.ts:17:17 #14314

Bersaelor opened this issue Sep 6, 2023 · 5 comments
Labels
cannot reproduce The bug cannot be reproduced pending triage

Comments

@Bersaelor
Copy link

Describe the bug

Was using vite to develop a site with no problems for weeks.

Suddenly I'm getting Uncaught ReferenceError: __DEFINES__ is not defined at env.ts:17:17

in that line in env.ts it says:

// assign defines
const defines = __DEFINES__

I have not changed my code in any way, I can also go back in my git history to any point in time, run

rm -rf node_modules
rm yarn.lock
yarn install

it'll still show the error.

So It can't have anything to do with my project setup, or the vite.config etc, since those worked fine for weeks now.

If I use a different macbook, with the same git repo, it works fine.

vite build also works fine, it's only the development build that shows this problem when starting http://localhost:5173/

Reproduction

no reproduction

Steps to reproduce

reproduction only possible on one machine

System Info

System:
    OS: macOS 13.5.1
    CPU: (8) arm64 Apple M1
    Memory: 187.33 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.14.0 - ~/.nvm/versions/node/v18.14.0/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 9.4.2 - ~/.nvm/versions/node/v18.14.0/bin/npm
  Browsers:
    Chrome: 116.0.5845.140
    Edge: 116.0.1938.69
    Safari: 16.6
  npmPackages:
    vite: ^4.4.7 => 4.4.9

Used Package Manager

yarn

Logs

Uncaught ReferenceError: DEFINES is not defined
at env.ts:17:17

Validations

@Bersaelor
Copy link
Author

The only way to fix it was to delete the project folder and do a clean git clone from the remote source.

Which kind of hidden caches does vite use that we could delete?

I have seen other people have this bug so clearly it happens intermittently.
Some vite-related file gets out of whack and needs to be reset.

@Bersaelor
Copy link
Author

Here's my gitignore in case this could help:

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

.aws-sam/

@sun0day
Copy link
Member

sun0day commented Sep 7, 2023

env.ts is injected by vite, __DEFINES__ should be replaced with defined env variables, can you help debug it deeper and provide more informations in your machine? Thanks

Find source code below in node_modules/vite/dist/node/chunks/*.js and add a log statement.

 transform(code, id, options) {
    console.log(id, normalizedClientEntry, normalizedEnvEntry) // <- add log here
    // env variables should be injected when rollup find `env.ts` related `id`
    if (id === normalizedClientEntry || id === normalizedEnvEntry) {  
        return injectConfigValues(code);
     }

Then you can provide the log info here and let's see whether there are some unexpected behaivors before injectConfigValues

@sapphi-red sapphi-red added the cannot reproduce The bug cannot be reproduced label Sep 10, 2023
@abrighton
Copy link

abrighton commented Sep 19, 2023

I am getting the same error after updating dependencies.
In the project (public repo: https://github.com/tmtsoftware/esw-ocs-eng-ui/tree/branch-0.4.x),
I run:

npm install
npm run build
npm run test:unit -- --config wtr-rtm.config.js

[email protected] test:unit
web-test-runner 'test/**/*.unit.test.{ts,tsx}' --config wtr-rtm.config.js

Test started with RTM enabled
Group by utility
✓ returns empty map
✓ returns grouped data by given getter function

Stream hook
✓ should run streaming call on render

test/hooks/useAuth.unit.test.tsx:

🚧 Browser logs:
ReferenceError: DEFINES is not defined
at node_modules/vite/dist/client/env.ts:17:16

❌ Could not import your test module. Check the browser logs or open the browser in debug mode for more information.
...

This is on Ubuntu 22.04 and the same error occurs on GitHub actions with OS ubuntu-latest.

@sapphi-red
Copy link
Member

Closing for now as we were not able to reproduce and there's not enough information to work on this.

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Nov 7, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cannot reproduce The bug cannot be reproduced pending triage
Projects
None yet
Development

No branches or pull requests

4 participants