Nx: workspaceFileName() failed to give the correct filename when whe have @angular/cli as a dependency but using the workspace.json configuration file

Created on 2 Jan 2020  路  1Comment  路  Source: nrwl/nx

Prerequisites

Expected Behavior

workspaceFileName() should return workspace.json

Current Behavior

workspaceFileName() returns angular.json

Failure Information (for bugs)

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. create an nx project without angular
  2. npm install @angular/cli package
  3. nx dep-graph
  4. It will throw 'no such file or directory, open '.../angular.json'

Context

Please provide any relevant information about your setup:

nx --version 
8.9.0

A minimal reproduction scenario allows us to quickly confirm a bug (or point out coding problem) as well as confirm that we are fixing the right problem.

  1. create an nx project without angular
  2. npm install @angular/cli
  3. nx dep-graph

Failure Logs

Error: ENOENT: no such file or directory, open '.../angular.json'
at Object.openSync (fs.js:443:3)
at Object.readFileSync (fs.js:343:35)
at Object.readJsonFile (...node_modules\@nrwl\workspace\src\utils\fileutils.js:60:44)
at Object.readWorkspaceJson (...node_modules\@nrwl\workspace\src\command-line\shared.js:256:24)
at Object.generateGraph (...node_modules\@nrwl\workspace\src\command-line\dep-graph.js:29:36)
at Object.exports.commandsObject.yargs.usage.command.command.command.command.command.command.command.command.command.command.command.command.command.args [as handler]

core bug

Most helpful comment

This is still an issue in the latest (9.0.2).

As noted by @scallacs, it is the logic of workspaceFileName() that needs to change.

It is using a different heuristic compared to other areas of the Nx codebase to determine the configuration file name - it is checking if @angular/cli is present.

From my node_modules:

function workspaceFileName() {
    const packageJson = readPackageJson();
    if (packageJson.devDependencies['@angular/cli'] ||
        packageJson.dependencies['@angular/cli']) {
        return 'angular.json';
    }
    else {
        return 'workspace.json';
    }
}
exports.workspaceFileName = workspaceFileName;

I think starting an Nx repo with a workspace.json and then adding Angular later is a more unusual journey right now (which is why you are not hearing about this as often), but it just bit me :)

PS see you at ng-conf @FrozenPandaz!

>All comments

This is still an issue in the latest (9.0.2).

As noted by @scallacs, it is the logic of workspaceFileName() that needs to change.

It is using a different heuristic compared to other areas of the Nx codebase to determine the configuration file name - it is checking if @angular/cli is present.

From my node_modules:

function workspaceFileName() {
    const packageJson = readPackageJson();
    if (packageJson.devDependencies['@angular/cli'] ||
        packageJson.dependencies['@angular/cli']) {
        return 'angular.json';
    }
    else {
        return 'workspace.json';
    }
}
exports.workspaceFileName = workspaceFileName;

I think starting an Nx repo with a workspace.json and then adding Angular later is a more unusual journey right now (which is why you are not hearing about this as often), but it just bit me :)

PS see you at ng-conf @FrozenPandaz!

Was this page helpful?
0 / 5 - 0 ratings