nx.js using capacitor Cannot find module 'nx/src/utils/app-root'

1.2k Views Asked by At

In my NX project, I have a capacitor Angular 14 application, when using cap:sync, I get the following error which stomps me.

> nx run caregiver:sync:ios --verbose=true


 >  NX   Cannot find module 'nx/src/utils/app-root'

   Require stack:
   - /Users/yannickdesjardins/Documents/GitHub/nx-c4g/nx-c4g/node_modules/@nxtend/capacitor/node_modules/@nrwl/devkit/index.js
   - /Users/yannickdesjardins/Documents/GitHub/nx-c4g/nx-c4g/node_modules/@nxtend/capacitor/src/executors/cap/executor.js
   - /Users/yannickdesjardins/Documents/GitHub/nx-c4g/nx-c4g/node_modules/nx/src/config/workspaces.js
   - /Users/yannickdesjardins/Documents/GitHub/nx-c4g/nx-c4g/node_modules/nx/src/command-line/run.js
   - /Users/yannickdesjardins/Documents/GitHub/nx-c4g/nx-c4g/node_modules/nx/bin/run-executor.js

Error: Cannot find module 'nx/src/utils/app-root'
Require stack:
- /Users/yannickdesjardins/Documents/GitHub/nx-c4g/nx-c4g/node_modules/@nxtend/capacitor/node_modules/@nrwl/devkit/index.js
- /Users/yannickdesjardins/Documents/GitHub/nx-c4g/nx-c4g/node_modules/@nxtend/capacitor/src/executors/cap/executor.js
- /Users/yannickdesjardins/Documents/GitHub/nx-c4g/nx-c4g/node_modules/nx/src/config/workspaces.js
- /Users/yannickdesjardins/Documents/GitHub/nx-c4g/nx-c4g/node_modules/nx/src/command-line/run.js
- /Users/yannickdesjardins/Documents/GitHub/nx-c4g/nx-c4g/node_modules/nx/bin/run-executor.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/Users/yannickdesjardins/Documents/GitHub/nx-c4g/nx-c4g/node_modules/@nxtend/capacitor/node_modules/@nrwl/devkit/index.js:182:18)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)

My nx report is the following: I use node 16, nx 14 and capacitor 13. I have research on the subject but can't seem to find the right answer.

2

There are 2 best solutions below

0
On

I had the same issue, it was difficult to find an answer online. Here is how I fixed this issue

First ran the nx report, then checked the nx version and @nrwl/<package> versions are the same.

For me the nx version was 14.4.2 and the @nrwl/react was 14.8.2 this was causing the issue I believe. Changing the version of @nrwl/react to 14.4.2 fixed it for me. I just went ahead changed the @nrwl/node and @nrwl/js versions to 14.4.2 from 14.4.3 (say that I'm cautious)

0
On

It's also possible the module has simply moved and NX failed to migrate some of your code.

In my case, I had to replace instances of:

const { registerTsProject } = require('nx/src/utils/register');

with

const { registerTsProject } = require('nx/src/plugins/js/utils/register');