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

@nx/vite:build doesn't set NODE_ENV properly #27627

Closed
1 of 4 tasks
CreativeTechGuy opened this issue Aug 23, 2024 · 1 comment · Fixed by #28444
Closed
1 of 4 tasks

@nx/vite:build doesn't set NODE_ENV properly #27627

CreativeTechGuy opened this issue Aug 23, 2024 · 1 comment · Fixed by #28444
Assignees
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug

Comments

@CreativeTechGuy
Copy link

Current Behavior

NX loads my vite config, then loads vite, then passes my resolved vite config object to the vite build command. The vite build command will first set NODE_ENV to the appropriate value if it's not already set. But since my vite config reads that to determine parts of the config itself, it'll read NODE_ENV before vite has a chance to set it.

Expected Behavior

Without using NX, this exact same thing works fine since vite CLI would run, which would then pass the string path of my config to the build command which then sets the environment and then loads my config. I'd expect that NX would work the same way.

There may be other differences, but I'm specifically asking if NODE_ENV can be set in the NX executor to the appropriate value (eg: "production" in the case of the production build) before evaluating my config file.

GitHub Repo

No response

Steps to Reproduce

  1. Make a vite config which console.log(process.env.NODE_ENV)
  2. Run the vite build command with vanilla vite and observe the output ("production")
  3. Run the vite build command with NX vite executor and observe the output (undefined)

Nx Report

Node           : 20.14.0
OS             : win32-x64
Native Target  : x86_64-windows
npm            : 10.7.0
 
nx                 : 19.6.1
@nx/js             : 19.6.1
@nx/linter         : 19.6.1
@nx/eslint         : 19.6.1
@nx/workspace      : 19.6.1
@nx/devkit         : 19.6.1
@nx/esbuild        : 19.6.1
@nx/eslint-plugin  : 19.6.1
@nrwl/tao          : 19.6.1
@nx/vite           : 19.6.1
typescript         : 5.5.4

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@jaysoo jaysoo added the scope: bundlers Issues related to webpack, rollup label Sep 25, 2024
@jaysoo jaysoo closed this as completed in f9f3de0 Oct 17, 2024
jaysoo pushed a commit that referenced this issue Oct 17, 2024
…node env set #27627 (#28444)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
In the Vite Build Executor, we're using `loadConfigFromFile` from Vite
to get the config options.
The issue with this is that vite will not attempt to set `NODE_ENV`
which may be required by both the config file that is being loaded, and
other plugins.


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Use resolveConfig which does set NODE_ENV correctly


## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #27627
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: bundlers Issues related to webpack, rollup type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants