无法创建 nx 工作区

Posted

技术标签:

【中文标题】无法创建 nx 工作区【英文标题】:Failed to create nx workspace 【发布时间】:2021-06-29 00:14:45 【问题描述】:

我是 NX 的新手,甚至是 NodeJS 生态系统的新手。当我发现有趣的工具来搭建全栈应用程序开发时,NX 在哪里,然后我尝试了一下。但是我在创建 nx-workspace 的第一步总是失败。不对,我在 Windows Pro 64 位上使用 Node 版本 14.16 LTS 和 npm 版本 6.14.11。以下是错误:

    C:\Projects>npx create-nx-workspace --preset=angular
? Workspace name (e.g., org name)     hw
? Application name                    shop
? Default stylesheet format           CSS
? Default linter                      ESLint [ Modern linting tool ]
? Use Nx Cloud? (It's free and doesn't require registration.) No

>  NX  Nx is creating your workspace.

  To make sure the command works reliably in all environments, and that the preset is applied correctly,
  Nx will run "npm install" several times. Please wait.

added 229 packages from 170 contributors and audited 230 packages in 9.112s

32 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

- Creating your workspace
>  NX   ERROR  Something went wrong. Rerunning the command with verbose logging.

Failed to format: hw\angular.json
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
    at Function.from (buffer.js:333:9)
    at FsTree.write (C:\Users\PTGENTS\AppData\Local\Temp\tmp-11296frnzjs2oVb4Z\node_modules\@nrwl\tao\src\shared\tree.js:35:20)
    at writeJson (C:\Users\PTGENTS\AppData\Local\Temp\tmp-11296frnzjs2oVb4Z\node_modules\@nrwl\devkit\src\utils\json.js:32:10)
    at Object.updateJson (C:\Users\PTGENTS\AppData\Local\Temp\tmp-11296frnzjs2oVb4Z\node_modules\@nrwl\devkit\src\utils\json.js:44:5)
    at formatWorkspaceJson (C:\Users\PTGENTS\AppData\Local\Temp\tmp-11296frnzjs2oVb4Z\node_modules\@nrwl\workspace\src\generators\workspace\workspace.js:53:18)
    at Object.<anonymous> (C:\Users\PTGENTS\AppData\Local\Temp\tmp-11296frnzjs2oVb4Z\node_modules\@nrwl\workspace\src\generators\workspace\workspace.js:78:9)
    at Generator.next (<anonymous>)
    at fulfilled (C:\Users\PTGENTS\AppData\Local\Temp\tmp-11296frnzjs2oVb4Z\node_modules\tslib\tslib.js:114:62) 
  code: 'ERR_INVALID_ARG_TYPE'

UPDATE hw/nx.json
UPDATE hw/package.json
UPDATE hw/.vscode/extensions.json
UPDATE hw/angular.json

> hw@0.0.0 postinstall C:\Projects\hw
> node ./decorate-angular-cli.js


>  NX  Angular CLI has been decorated to enable computation caching.

npm WARN @cypress/webpack-preprocessor@4.1.5 requires a peer of webpack@^4.18.1 but none is installed. You must install peer dependencies yourself.
npm WARN @nrwl/cypress@11.6.1 requires a peer of cypress@>= 3 < 7 but none is installed. You must install peer dependencies yourself.
npm WARN babel-loader@8.2.2 requires a peer of webpack@>=2 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted "os":"darwin","arch":"any" (current: "os":"win32","arch":"x64")

removed 1506 packages and audited 799 packages in 21.916s

56 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities

MergeConflictException [Error]: A merge conflicted on path "/apps/shop/tsconfig.editor.json".
    at C:\Projects\hw\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:142:35
    at Array.forEach (<anonymous>)
    at HostTree.merge (C:\Projects\hw\node_modules\@angular-devkit\schematics\src\tree\host-tree.js:131:23)
    at MapSubscriber.project (C:\Projects\hw\node_modules\@angular-devkit\schematics\src\rules\base.js:54:91)
    at MapSubscriber._next (C:\Projects\hw\node_modules\rxjs\internal\operators\map.js:49:35)
    at MapSubscriber.Subscriber.next (C:\Projects\hw\node_modules\rxjs\internal\Subscriber.js:66:18)
    at TapSubscriber._next (C:\Projects\hw\node_modules\rxjs\internal\operators\tap.js:65:26)
    at TapSubscriber.Subscriber.next (C:\Projects\hw\node_modules\rxjs\internal\Subscriber.js:66:18)
    at ThrowIfEmptySubscriber._next (C:\Projects\hw\node_modules\rxjs\internal\operators\throwIfEmpty.js:44:26)
    at ThrowIfEmptySubscriber.Subscriber.next (C:\Projects\hw\node_modules\rxjs\internal\Subscriber.js:66:18)
A merge conflicted on path "/apps/shop/tsconfig.editor.json".
Workspace creation failed, see above.
(node:11296) UnhandledPromiseRejectionWarning: Error: Command failed: npx tao new hw --preset=angular --no-interactive --appName=shop --style=css --linter=eslint --no-nxCloud --collection=@nrwl/workspace/collection.json --cli=angular --nxWorkspaceRoot="C:/Projects"
    at checkExecSyncError (child_process.js:616:11)
    at Object.execSync (child_process.js:652:15)
    at C:\Users\PTGENTS\AppData\Roaming\npm\node_modules\create-nx-workspace\bin\create-nx-workspace.js:424:29
    at Generator.throw (<anonymous>)
    at rejected (C:\Users\PTGENTS\AppData\Roaming\npm\node_modules\create-nx-workspace\node_modules\tslib\tslib.js:113:69)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:11296) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:11296) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

谁能帮帮我或给我一个线索?

【问题讨论】:

遇到同样的问题。你解决了吗? @lego 还没有。不幸的是。 遇到同样的问题 .. any1 找到解决方法了吗? 我只能说我遇到了同样的问题,但我选择了scss - 将其更改为css 对我有用。 (我看到你选择了css,所以它没有帮助,但也许可以帮助下一个人。 【参考方案1】:

我在解决使用以下命令创建新工作区时遇到了同样的问题:-

npx create-nx-workspace --preset=angular --skip-git=true

【讨论】:

【参考方案2】:

我可以修复它

git config --global user.email "you@example.com"
git config --global user.name "Your Name"

设置电子邮件npx create-nx-workspace 后工作。

【讨论】:

【参考方案3】:

我在第一次这样做时也遇到了同样的问题。但后来它奏效了。 请遵循以下内容。

确保您拥有节点最新版本 安装 Angular cli [npm install -g @angular/cli] 安装nrwl原理图[npm install -g @nrwl/schematics]

我按照这些步骤操作,现在一切正常。

您可以参考此link 进行初始设置。

【讨论】:

【参考方案4】:

确保您的互联网连接正常。在我的情况下,代理设置被破坏了

【讨论】:

我很确定我的互联网连接没有问题。

以上是关于无法创建 nx 工作区的主要内容,如果未能解决你的问题,请参考以下文章

为啥 nrwl nx 为每个应用程序创建一个单独的 e2e 项目?

Angular Nx Nrwl - 尝试创建新库时无法解析 tsconfig.base.json:JSON 中的 PropertyNameExpected

nrwl/nx 原理图创建 Angular 应用程序并配置 Angular json

我可以在一个 Nx 工作区中将 NX CLI 用于 Angular 和 React 应用程序吗?

scss 样式未在 nx 角度工作区库中应用

无法在我的 NX 工作区中使用 @angular-service-worker