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

vite.config.ts files may not be within project folder otherwise wrong vite.config.ts is used #29487

Open
1 of 4 tasks
bubblegumsoldier opened this issue Dec 30, 2024 · 0 comments

Comments

@bubblegumsoldier
Copy link

Current Behavior

I have the following project structure

apps/
  mika-app-fe/
    project.json
    vite.config.ts
  mika-controlplane-fe/
    project.json
    vite.config.ts

apps/mika-app-fe/project.json

{
  "name": "mika-app-fe",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/mika-app-fe/src",
  "projectType": "application",
  "tags": [],
  "targets": {
    "build": {
      "executor": "@nx/vite:build",
      "options": {
        "outputPath": "../../dist/apps/mika-app-fe",
        "configFile": "apps/mika-app-fe/vite.config.ts"
      }
    }
  }
}

apps/mika-controlplane/project.json

{
  "name": "mika-controlplane-fe",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/mika-controlplane-fe/src",
  "projectType": "application",
  "tags": [],
  "targets": {
    "build": {
      "executor": "@nx/vite:build",
      "options": {
        "outputPath": "dist/apps/mika-controlplane-fe",
        "configFile": "apps/mika-controlplane-fe/vite.config.ts"
      }
    }
  }
}

The problem is when I now run npx nx build mika-controlplane-fe --skip-nx-cache --verbose it tries to use the mika-app-fe/vite.config.ts instead of the mika-controlplane-fe/vite.config.ts. Both configs however required different vite environment variables, so that breaks the build.

Full output:

[Nx Vite TsPaths] Found tsconfig at /home/runner/work/mika-app-fe/mika-app-fe/tsconfig.base.json

[Nx Vite TsPaths] first parsed tsconfig:  {
  resultType: 'success',
  configFileAbsolutePath: '/home/runner/work/mika-app-fe/mika-app-fe/tsconfig.base.json',
  baseUrl: '.',
  absoluteBaseUrl: '/home/runner/work/mika-app-fe/mika-app-fe',
  paths: {},
  addMatchAll: true
}

[Nx Vite TsPaths] Found tsconfig at /home/runner/work/mika-app-fe/mika-app-fe/tsconfig.base.json

[Nx Vite TsPaths] fallback parsed tsconfig:  {
  resultType: 'success',
  configFileAbsolutePath: '/home/runner/work/mika-app-fe/mika-app-fe/tsconfig.base.json',
  baseUrl: '.',
  absoluteBaseUrl: '/home/runner/work/mika-app-fe/mika-app-fe',
  paths: {},
  addMatchAll: true
}
failed to load config from /home/runner/work/mika-app-fe/mika-app-fe/apps/mika-app-fe/vite.config.ts

 NX   Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it. See errors below.

Failed to process project graph. Run "nx reset" to fix this. Please report the issue if you keep seeing it.
      An error occurred while processing files for the @nx/vite/plugin plugin.
    - apps/mika-app-fe/vite.config.ts: You are missing the google maps API key in your .env file
      Error: You are missing the google maps API key in your .env file
          at /home/runner/work/mika-app-fe/mika-app-fe/apps/mika-app-fe/vite.config.ts:72:[11](https://github.com/mikaaccounting/mika-app-fe/actions/runs/12545768957/job/34980503144#step:6:12)
          at loadConfigFromFile (file:///home/runner/work/mika-app-fe/mika-app-fe/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:66538:62)
          at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
          at async resolveConfig (file:///home/runner/work/mika-app-fe/mika-app-fe/node_modules/vite/dist/node/chunks/dep-CB_7IfJ-.js:66140:24)
          at async buildViteTargets (/home/runner/work/mika-app-fe/mika-app-fe/node_modules/@nx/vite/src/plugins/plugin.js:1[13](https://github.com/mikaaccounting/mika-app-fe/actions/runs/12545768957/job/34980503144#step:6:14):29)
          at async createNodesInternal (/home/runner/work/mika-app-fe/mika-app-fe/node_modules/@nx/vite/src/plugins/plugin.js:79:18)
          at async /home/runner/work/mika-app-fe/mika-app-fe/node_modules/nx/src/project-graph/plugins/utils.js:10:27
          at async Promise.all (index 0)
          at async createNodesFromFiles (/home/runner/work/mika-app-fe/mika-app-fe/node_modules/nx/src/project-graph/plugins/utils.js:8:5)
          at async Array.createNodesV2 (/home/runner/work/mika-app-fe/mika-app-fe/node_modules/@nx/vite/src/plugins/plugin.js:50:[20](https://github.com/mikaaccounting/mika-app-fe/actions/runs/12545768957/job/34980503144#step:6:21))

The You are missing the google maps API key in your .env file issue only is thrown in the mika-app-fe/vite.config.ts, but I am building the controlplane-version.

Workaround

I have found a workaround:

I moved the vite.config.ts to the project root level like this

apps/
  mika-app-fe/
    project.json
  mika-controlplane-fe/
    project.json
  
  vite.config.app.ts
  vite.config.controlplane.ts

and adapted the configs

apps/mika-app-fe/project.json

{
  "name": "mika-app-fe",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/mika-app-fe/src",
  "projectType": "application",
  "tags": [],
  "targets": {
    "build": {
      "executor": "@nx/vite:build",
      "options": {
        "outputPath": "dist/apps/mika-app-fe",
        "configFile": "vite.config.app.ts"
      }
    }
  }
}

apps/mika-controlplane/project.json

{
  "name": "mika-controlplane-fe",
  "$schema": "../../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "apps/mika-controlplane-fe/src",
  "projectType": "application",
  "tags": [],
  "targets": {
    "build": {
      "executor": "@nx/vite:build",
      "options": {
        "outputPath": "dist/apps/mika-controlplane-fe",
        "configFile": "vite.config.controlplane.ts"
      }
    }
  }
}

Expected Behavior

I would expect that I can have a vite.config.ts within each of my apps, to specify specific vite build requirements, such as envs and that it then only uses the one that I am building

GitHub Repo

No response

Steps to Reproduce

Unsure how to reproduce.

Nx Report

NX   Report complete - copy this into the issue template

Node           : 21.6.2
OS             : win32-x64
Native Target  : x86_64-windows
yarn           : 1.22.22

nx (global)            : 20.2.2
nx                     : 20.2.2
@nx/js                 : 20.2.2
@nx/jest               : 20.2.2
@nx/eslint             : 20.2.2
@nx/workspace          : 20.2.2
@nx/devkit             : 20.2.2
@nx/eslint-plugin      : 20.2.2
@nx/module-federation  : 20.2.2
@nx/playwright         : 20.2.2
@nx/react              : 20.2.2
@nx/vite               : 20.2.2
@nx/web                : 20.2.2
@nx/webpack            : 20.2.2
typescript             : 5.6.3
---------------------------------------
Registered Plugins:
@nx/vite/plugin
@nx/eslint/plugin
@nx/playwright/plugin
@nx/jest/plugin

Failure Logs

Package Manager Version

No response

Operating System

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

Additional Information

This happened only on CI for some reason.

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

No branches or pull requests

1 participant