Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nx missing dependencies on generated package.json

I've setup a basic publishable lib using @nrwl/react:

nx g @nrwl/react:lib my-new-lib --publishable --importPath=@myorg/my-new-lib

Then installed MUI in the monorepo root:

npm install @mui/material @emotion/react @emotion/styled

And imported a MUI component:

import { Button } from '@mui/material';

export function MyNewLib() {
  return (
    <div>
      <h1>Welcome to MyNewLib!</h1>
      <Button>Hello</Button>
    </div>
  );
}

export default MyNewLib;

Finally I build the library using:

nx run my-new-lib:build

And this is the generated package.json:

{
  "name": "@myorg/my-new-lib",
  "version": "0.0.1",
  "module": "./index.js",
  "main": "./index.js",
  "type": "module",
  "types": "./index.d.ts"
}

MUI dependencies are not added to the generated package.json.

What I'm missing?

Here is a repo if you want to try it:

  • https://github.com/oncet/nx-playground
like image 967
Camilo Avatar asked Jan 19 '26 18:01

Camilo


1 Answers

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"
like image 191
Camilo Avatar answered Jan 21 '26 23:01

Camilo