Nrwl Nx build for production 缺少节点模块包

Nrwl Nx build for production missing node modules bundle

我有一个 Nrwl Nx 存储库,其中包含不同的应用程序(angular、带有 express 的 nodejs)和内部共享库。 该回购是使用 nx cli 创建的,我想为生产构建 express 应用程序之一。

nx build:production myexpressapp

我得到的包非常好,如果我 运行 它(使用 pm2)来自它的构建位置(dist 文件夹),那么 运行s。 但是,如果我将其投入生产,节点模块就会丢失,应用程序也不会启动。 如果我将 node_modules 文件夹复制到具有内置 dist 的文件夹上方,它也可以正常工作。

但我非常想要:

我尝试在生产构建选项中使用 "vendorChunk":true,但没有任何变化。

有什么想法吗?

查看 angular.json(或 workspace.json),如果您的 builder@nrwl/node:build,在 options 下,将 externalDependencies 设置为 none,像这样:

{
  "projects": {
    "api": {
      "architect": {
        "build": {
          "builder": "@nrwl/node:build",
          "options": {
            "externalDependencies": "none"
            ...

您可能会遇到如下错误:

ERROR in ...
Module not found: Error: Can't resolve 'some-modules' in ...

继续安装它抱怨的东西,直到它停止。

参考:Nrwl Nx Node Builder