nx: After replacing `vite-tsconfig-paths` by `@nx/vite/plugins/nx-tsconfig-paths.plugin` => `app:serve` target throws errors

Current Behavior

After replacing vite-tsconfig-paths by @nx/vite/plugins/nx-tsconfig-paths.plugin app:serve target throws errors

As a workaround I have to include this piece of config to the vite.config.ts of the app, which is feels and looks bad to me 🀷

    optimizeDeps: {
      exclude: [
        '@swc-node/register',
        '@angular-devkit',
        'webpack',
        '@nx/nx-win32-x64-msvc',
        '@nx/nx-darwin-arm64',
      ],
    },

NB: build:prod target works flawlessly, only serve target is throwing errors

Expected Behavior

There should be no errors in console, just like it was before drop-in replacement of the vite-tsconfig-paths by @nx/vite/plugins/nx-tsconfig-paths.plugin

GitHub Repo

No response

Steps to Reproduce

  1. Upgrade to latest nx 16.6.0
  2. Replace vite-tsconfig-paths by @nx/vite/plugins/nx-tsconfig-paths.plugin in vite.config.ts
  3. nx run app:serve:development throws a lot of errors and fails to serve the app
  4. nx run app:build:production works fine and produces app artifacts w/o errors

Nx Report

Node   : 16.15.0
   OS     : win32-x64
   yarn   : 1.22.19
   
   nx                 : 16.6.0
   @nx/js             : 16.6.0
   @nx/linter         : 16.6.0
   @nx/workspace      : 16.6.0
   @nx/cypress        : 16.6.0
   @nx/devkit         : 16.6.0
   @nx/eslint-plugin  : 16.6.0
   @nx/storybook      : 16.6.0
   @nrwl/tao          : 16.6.0
   @nx/vite           : 16.6.0
   typescript         : 5.1.6
   ---------------------------------------

Failure Logs

➜  Local:   http://localhost:4200/
  ➜  Network: http://192.168.0.169:4200/    
[vite-plugin-static-copy] Collected 2 items.
X [ERROR] Could not resolve "@angular-devkit/architect"

    node_modules/@nx/devkit/src/utils/convert-nx-executor.js:41:19:
      41 β”‚     return require('@angular-devkit/architect').createBuilder(builderFunction);
         β•΅                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@angular-devkit/architect" as external to exclude it from the bundle, which
  will remove this error. You can also surround this "require" call with a try/catch block to handle
  this failure at run-time instead of bundle-time.

X [ERROR] Could not resolve "webpack"

    node_modules/@nx/devkit/src/utils/module-federation/share.js:44:28:
      44 β”‚     const webpack = require('webpack');
         β•΅                             ~~~~~~~~~

  You can mark the path "webpack" as external to exclude it from the bundle, which will remove this
  error. You can also surround this "require" call with a try/catch block to handle this failure at
  run-time instead of bundle-time.

X [ERROR] Could not resolve "@angular-devkit/core"

    node_modules/nx/src/adapter/ngcli-adapter.js:5:23:
      5 β”‚ const core_1 = require("@angular-devkit/core");
        β•΅                        ~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@angular-devkit/core" as external to exclude it from the bundle, which will
  remove this error. You can also surround this "require" call with a try/catch block to handle this
  failure at run-time instead of bundle-time.

X [ERROR] Could not resolve "@angular-devkit/core/node"

    node_modules/nx/src/adapter/ngcli-adapter.js:6:23:
      6 β”‚ const node_1 = require("@angular-devkit/core/node");
        β•΅                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@angular-devkit/core/node" as external to exclude it from the bundle, which
  will remove this error. You can also surround this "require" call with a try/catch block to handle
  this failure at run-time instead of bundle-time.

X [ERROR] No known conditions for "./read-default-tsconfig" specifier in "@swc-node/register" package [plugin vite:dep-pre-bundle]

    node_modules/nx/src/plugins/js/utils/register.js:115:49:
      115 β”‚         const { readDefaultTsConfig, } = require('@swc-node/register/read-default-tsconfig');
          β•΅                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  This error came from the "onResolve" callback registered here:

    node_modules/vite/node_modules/esbuild/lib/main.js:1292:20:
      1292 β”‚       let promise = setup({
           β•΅                     ^

    at setup (file:///C:/Users/omazuruk/Documents/GitHub/agent-ui/node_modules/vite/dist/node/chunks/dep-df561101.js:39921:19)
    at handlePlugins (C:\Users\omazuruk\Documents\GitHub\agent-ui\node_modules\vite\node_modules\esbuild\lib\main.js:1292:21)
    at buildOrContextImpl (C:\Users\omazuruk\Documents\GitHub\agent-ui\node_modules\vite\node_modules\esbuild\lib\main.js:978:5)
    at Object.buildOrContext (C:\Users\omazuruk\Documents\GitHub\agent-ui\node_modules\vite\node_modules\esbuild\lib\main.js:786:5)        
    at C:\Users\omazuruk\Documents\GitHub\agent-ui\node_modules\vite\node_modules\esbuild\lib\main.js:2186:68
    at new Promise (<anonymous>)
    at Object.context (C:\Users\omazuruk\Documents\GitHub\agent-ui\node_modules\vite\node_modules\esbuild\lib\main.js:2186:27)
    at Object.context (C:\Users\omazuruk\Documents\GitHub\agent-ui\node_modules\vite\node_modules\esbuild\lib\main.js:2026:58)
    at prepareEsbuildOptimizerRun (file:///C:/Users/omazuruk/Documents/GitHub/agent-ui/node_modules/vite/dist/node/chunks/dep-df561101.js:45967:35)

X [ERROR] Could not resolve "@angular-devkit/architect"

    node_modules/nx/src/adapter/ngcli-adapter.js:37:38:
      37 β”‚         const { Architect } = require('@angular-devkit/architect');
         β•΅                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@angular-devkit/architect" as external to exclude it from the bundle, which
  will remove this error. You can also surround this "require" call with a try/catch block to handle
  this failure at run-time instead of bundle-time.

X [ERROR] Could not resolve "@angular-devkit/schematics/tools"

    node_modules/nx/src/adapter/ngcli-adapter.js:112:33:
      112 β”‚     const NodeWorkflow = require('@angular-devkit/schematics/tools').NodeWorkflow;
          β•΅                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@angular-devkit/schematics/tools" as external to exclude it from the
  bundle, which will remove this error. You can also surround this "require" call with a try/catch
  block to handle this failure at run-time instead of bundle-time.

X [ERROR] Could not resolve "@angular-devkit/schematics"

    node_modules/nx/src/adapter/ngcli-adapter.js:118:63:
      118 β”‚         registry: new core_1.schema.CoreSchemaRegistry(require('@angular-devkit/schematics').formats.standardFormats),
          β•΅                                                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  You can mark the path "@angular-devkit/schematics" as external to exclude it from the bundle,
  which will remove this error. You can also surround this "require" call with a try/catch block to
  handle this failure at run-time instead of bundle-time.

X [ERROR] Could not resolve "@angular-devkit/architect/node"

    node_modules/nx/src/adapter/ngcli-adapter.js:722:140:
      722 β”‚ ...ngularWorkspaceNodeModulesArchitectHost, } = yield Promise.resolve().then(() => require('@angular-devkit/architect/node')); 
          β•΅                                                                                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    

  You can mark the path "@angular-devkit/architect/node" as external to exclude it from the bundle,
  which will remove this error. You can also surround this "require" call with a try/catch block to
  handle this failure at run-time instead of bundle-time.

X [ERROR] No loader is configured for ".node" files: node_modules/@nx/nx-win32-x64-msvc/nx.win32-x64-msvc.node

    node_modules/nx/src/native/index.js:66:36:
      66 β”‚             nativeBinding = require('@nx/nx-win32-x64-msvc')
         β•΅                                     ~~~~~~~~~~~~~~~~~~~~~~~

X [ERROR] Could not resolve "@swc/wasm"

    node_modules/@swc/core/index.js:70:35:
      70 β”‚         fallbackBindings = require('@swc/wasm');
         β•΅                                    ~~~~~~~~~~~

  You can mark the path "@swc/wasm" as external to exclude it from the bundle, which will remove
  this error. You can also surround this "require" call with a try/catch block to handle this
  failure at run-time instead of bundle-time.

X [ERROR] No loader is configured for ".node" files: node_modules/@swc/core-win32-x64-msvc/swc.win32-x64-msvc.node

    node_modules/@swc/core/binding.js:68:48:
      68 β”‚                         nativeBinding = require('@swc/core-win32-x64-msvc');
         β•΅                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~

Operating System

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

Additional Information

No response

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 20 (9 by maintainers)

Most upvoted comments

@barbados-clemens interestingly though, it doesn’t happen anymore in our codebase 🀷 I’ve traced down the commit which is flipping the behaviour, now i’m trying to revert file by file to get to the root cause πŸ˜„

Then it must be something specific to how we are handling things. I’ll have to dig into the vite-tsconfig-paths plugin to see what we are missing. Explains why that plugin is more complex than I expected when first looking at it. πŸ˜