compiler-errorsivynrwl-nxnrwl

Error: Could not find 'nx' module in this workspace


In trying to build an app I am getting the following error: Compiling with Angular sources in Ivy partial compilation mode. Could not find 'nx' module in this workspace. TypeError: (intermediate value)(intermediate value)(intermediate value).split is not a function

I am using nx 16.10.0.

I can't locate any information on this. Can somebody tell me how to fix this error.

Thank you, Al


Solution

  • This error message is super misleading. My real issue was a misconfigured library. The stack trace that you're getting is likely for an error thrown during error processing, not the stack trace for the original error, which is what is causing the problem.

    You'll see that the first frame of the stack trace is the file /node_modules/nx/src/utils/params.js:17 (exact path may vary slightly depending on your package manager). Open this file and add a console log of the whole err.message object before line 17. In my case, this revealed the real error that NX was choking on:

    {
      category: 3,
      code: 0,
      messageText: 'Unable to import symbol ClickOutsideDirective.',
      next: [
        {
          category: 3,
          code: 0,
          messageText: "The file <projectRoot>/libs/shared/ui-click-outside-directive/src/lib/click-outside.directive.ts is outside of the configured 'rootDir'.",
          next: undefined
        }
      ]
    }
    

    That should give you a good place to start investigating where your misconfiguration is. In my case, the library name in the library's package.json file didn't match the library name in my tsconfig.base.json file. Updating the name in the library's package.json file fixed the problem. Hopefully NX will fix this issue with their error logging at some point.