nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.29k stars 2.32k forks source link

"this.tree.readText is not a function" error after updating nrwl/angular to 14.2.4 #10678

Closed chioarub closed 2 years ago

chioarub commented 2 years ago

After installing "@nrwl/angular": "^14.2.4" I am not able to use the Nx Console or the CLI to generate Angular applications

Current Behavior

TypeError when generating Angular applications using Cli/NxConsole plugin

Expected Behavior

Generate Angular applications using Cli/NxConsole plugin

Steps to Reproduce

  1. generate nx workspace using npx create-nx-workspace test-workspace
  2. install nrwl Angular dependency npm install -D @nrwl/angular
  3. generate Angular application using cli or NxConsole plugin npx nx generate @nrwl/angular:application web-ui --style=scss --port=4200 --routing --standaloneConfig --no-interactive --dry-run

Failure Logs

run npx nx generate @nrwl/angular:application web-ui --style=scss --port=4200 --routing --standaloneConfig --no-interactive --dry-run

> NX Generating @nrwl/angular:application

TypeError: this.tree.readText is not a function at TreeWorkspaceHost.readFile (D:\Projects\Ts\Personal\test-workspace\node_modules\@schematics\angular\utility\workspace.js:23:26) at readJsonWorkspace (D:\Projects\Ts\Personal\test-workspace\node_modules\@schematics\angular\node_modules\@angular-devkit\core\src\workspace\json\reader.js:17:28) at Object.readWorkspace (D:\Projects\Ts\Personal\test-workspace\node_modules\@schematics\angular\node_modules\@angular-devkit\core\src\workspace\core.js:91:62) at async getWorkspace (D:\Projects\Ts\Personal\test-workspace\node_modules\@schematics\angular\utility\workspace.js:73:27) at async D:\Projects\Ts\Personal\test-workspace\node_modules\@schematics\angular\application\index.js:224:27

this.tree.readText is not a function

Environment

Windows 11 Node : 14.19.3 OS : win32 x64 npm : 6.14.17

nx : 14.2.4 @nrwl/angular : 14.2.4 @nrwl/cypress : 14.2.4 @nrwl/detox : Not Found @nrwl/devkit : 14.2.4 @nrwl/eslint-plugin-nx : Not Found @nrwl/express : Not Found @nrwl/jest : 14.2.4 @nrwl/js : 14.2.4 @nrwl/linter : 14.2.4 @nrwl/nest : 14.2.4 @nrwl/next : Not Found @nrwl/node : 14.2.4 @nrwl/nx-cloud : Not Found @nrwl/nx-plugin : Not Found @nrwl/react : Not Found @nrwl/react-native : Not Found @nrwl/schematics : Not Found @nrwl/storybook : 14.2.4 @nrwl/web : Not Found @nrwl/workspace : 14.2.4 typescript : 4.7.3

Community plugins:

Coly010 commented 2 years ago

I can't reproduce this on MacOS with latest. I believe it might be an OS-specific issue for windows.

Coly010 commented 2 years ago

Update, I cannot reproduce this on Windows either.

@chioarub Can you share the version of the Angular CLI that is within your workspace? And also could you share the output of running npm ls @schematics/angular?

xMonkfish commented 2 years ago

I am also experiencing this error since migrating to 14.2.4 in addition I also get a similar error when trying to create a lazy loaded module

`> Executing task: npx nx generate @schematics/angular:module test --module=app-routing --route=test2 --routing --no-interactive --dry-run <

NX Generating @schematics/angular:module

[NX] Angular devkit readJsonWorkspace fell back to Nx workspaces logic TypeError: host.readText is not a function at C:\repos\test-repo\testproj\node_modules\@schematics\angular\module\index.js:84:33 at MergeMapSubscriber.project (C:\repos\test-repo\testproj\node_modules\@schematics\angular\node_modules\@angular-devkit\schematics\src\rules\call.js:75:24) at MergeMapSubscriber._tryNext (C:\repos\test-repo\testproj\node_modules\@schematics\angular\node_modules\rxjs\internal\operators\mergeMap.js:67:27)
at MergeMapSubscriber._next (C:\repos\test-repo\testproj\node_modules\@schematics\angular\node_modules\rxjs\internal\operators\mergeMap.js:57:18)
at MergeMapSubscriber.Subscriber.next (C:\repos\test-repo\testproj\node_modules\@schematics\angular\node_modules\rxjs\internal\Subscriber.js:66:18)
at MergeMapSubscriber.notifyNext (C:\repos\test-repo\testproj\node_modules\@schematics\angular\node_modules\rxjs\internal\operators\mergeMap.js:93:26)
at SimpleInnerSubscriber._next (C:\repos\test-repo\testproj\node_modules\@schematics\angular\node_modules\rxjs\internal\innerSubscribe.js:27:21)
at SimpleInnerSubscriber.Subscriber.next (C:\repos\test-repo\testproj\node_modules\@schematics\angular\node_modules\rxjs\internal\Subscriber.js:66:18)
at Observable._subscribe (C:\repos\test-repo\testproj\node_modules\@schematics\angular\node_modules\rxjs\internal\util\subscribeToArray.js:5:20)
at Observable._trySubscribe (C:\repos\test-repo\testproj\node_modules\@schematics\angular\node_modules\rxjs\internal\Observable.js:44:25) host.readText is not a function The terminal process "C:\Program Files\PowerShell\7\pwsh.exe -Command npx nx generate @schematics/angular:module test --module=app-routing --route=test2 --routing --no-interactive --dry-run" terminated with exit code: 1.`

npm ls @schematics/angular Info @angular/cli@14.0.1 @schematics/angular@14.0.1 @nrwl/angular@14.2.4 @schematics/angular@14.0.1 deduped

Environment

` Node : 16.13.2 OS : win32 x64 npm : 8.1.2

nx : 14.2.4 @nrwl/angular : 14.2.4 @nrwl/cypress : 14.2.4 @nrwl/detox : Not Found @nrwl/devkit : 14.2.4 @nrwl/eslint-plugin-nx : 14.2.4 @nrwl/express : Not Found @nrwl/jest : 14.2.4 @nrwl/js : Not Found @nrwl/linter : 14.2.4 @nrwl/nest : Not Found @nrwl/next : Not Found @nrwl/node : Not Found @nrwl/nx-cloud : Not Found @nrwl/nx-plugin : Not Found @nrwl/react : Not Found @nrwl/react-native : Not Found @nrwl/schematics : Not Found @nrwl/storybook : 14.2.4 @nrwl/web : Not Found @nrwl/workspace : 14.2.4 typescript : 4.7.3

Community plugins: @ngrx/effects: 14.0.0-rc.0 @ngrx/router-store: 14.0.0-rc.0 @ngrx/store: 14.0.0-rc.0 @ngrx/store-devtools: 14.0.0-rc.0 eslint-plugin-ngrx: 2.1.2`

chioarub commented 2 years ago

@Coly010 There is no Angular CLI installed in the workspace. It will get installed once I generate the project, which at the moment I cannot do, due to the cli/NxConsole issue. Output of npm ls @schematics/angular is `-- @nrwl/angular@14.2.4

-- @schematics/angular@14.0.1`

chioarub commented 2 years ago

Removing node_modules and reinstalling got it working. Issue can be closed.

tunecino commented 2 years ago

Same error here when running a dry run of npx nx generate @nrwl/angular:library.

Nx: 14.4.0-beta.1
Node: 18.4.0
npm: 8.13.1
OS: macOS 11.5.2 arm64 (M1)

Removing node_modules didn't fix it for me. In my case, the solution was to add @angular-devkit/schematics as a dev dependency. That fixed it.

gib commented 1 year ago

Thank you @tunecino, that's what I needed too

Bhargav210592 commented 1 year ago

i already have @angular-devkit/schematics then also issue is not solved

pdavie commented 1 year ago

Adding @angular-devkit/schematics as a dev dependency fixed it for me also.

Emkacf commented 1 year ago

@Bhargav210592 did you fix your issue? I have the same problem.

webia1 commented 1 year ago
yarn add -D @angular-devkit/schematics 
github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.