npmmonoreponrwl-nx

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:


Solution

  • 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"