添加 @nx/webpack 插件会破坏 Nativescript 构建

问题描述 投票:0回答:1

我有一个集成的 NX 工作区,其中有一个 Angular 应用程序和一个 Nativescript 应用程序。我正在尝试通过

@nx/nest
添加 Nest.js 应用程序。每当我添加新应用程序时,它都会安装
@nx/webpack
插件并将该插件添加到
nx.json
。我注意到 Nativescript 使用自己的
@nativescript/webpack
模块。

每当我尝试构建或提供任何应用程序时,它都会立即抛出类型错误,因为它试图将

@nx/webpack
与 Nativescript 一起使用...这是错误

 NX   Unable to create nodes for apps/nativescript-mobile-app/webpack.config.js using plugin @nx/webpack/plugin. 


         Inner Error: TypeError [ERR_INVALID_ARG_TYPE]: The "paths[1]" argument must be of type string. Received undefined

有人遇到过 Webpack 模块冲突的问题吗?是否可以指定哪些应用程序使用 NX 插件?

angular webpack nativescript nrwl-nx
1个回答
0
投票

@rthames62 在官方 Discord 服务器上提到了他的问题,并向我提供了他的

nx.json
以及他的 NestJS
project.json

如果这里的其他人也面临这个问题;

添加

@nx/nest
似乎是将全局
@nx/webpack/plugin
添加到您的
nx.json
中,而不是将其添加到 NestJS
project.json
作为目标:

  "plugins": [
    {
      "plugin": "@nx/webpack/plugin",
      "options": {
        "buildTargetName": "build",
        "serveTargetName": "serve",
        "previewTargetName": "preview"
      }
    },
    {
      "plugin": "@nx/eslint/plugin",
      "options": {
        "targetName": "lint"
      }
    }
  ]

只需删除

@nex/webpack/plugin
条目即可。

现在将其添加到您的 NestJS

project.json
:

    "build": {
      "executor": "@nx/webpack:webpack",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        "target": "node",
        "compiler": "tsc",
        "outputPath": "dist/apps/YOUR NEST APP",
        "main": "apps/YOUR NEST APP/src/main.ts",
        "tsConfig": "apps/YOUR NEST APP/tsconfig.app.json",
        "assets": ["apps/YOUR NEST APP/src/assets"],
        "webpackConfig": "apps/YOUR NEST APP/webpack.config.js"
      },
      "target": "node",
      "compiler": "tsc",
      "configurations": {
        "development": {
        },
        "production": {
        }
      }
    }

如果您在提供 NestJS 应用程序时遇到问题,请将 NestJS

serve
project.json
目标更改为:


    "serve": {
      "executor": "@nx/js:node",
      "defaultConfiguration": "development",
      "options": {
        "buildTarget": "YOUR NEST APP:build"
      },
      "target": "node",
      "compiler": "tsc",
      "configurations": {
        "development": {
          "buildTarget": "YOUR NEST APP:build:development"
        },
        "production": {
          "buildTarget": "YOUR NEST APP:build:production"
        }
      }
    }

请记住将

YOUR NEST APP
更改为您的 NestJS 应用程序的名称。

很高兴我能提供帮助。

© www.soinside.com 2019 - 2024. All rights reserved.