I had a similar problem and solved by adding this to my `nx.json`:
```
"pluginsConfig": {
"@nrwl/js": {
"analyzeSourceFiles": true
}
}
```
And this two options to my `build` target (I'm using `@nrwl/web:rollup`) in the `project.json`:
```
"updateBuildableProjectDepsInPackageJson": true,
"buildableProjectDepsInPackageJsonType": "dependencies"
```
Finally found a solution, adding this to my `nx.json`:
```
"pluginsConfig": {
"@nrwl/js": {
"analyzeSourceFiles": true
}
}
```
And this two options to my `build` target (I'm using `@nrwl/web:rollup`) in the `project.json`:
```
"updateBuildableProjectDepsInPackageJson": true,
"buildableProjectDepsInPackageJsonType": "dependencies"
```