Questions tagged [npm-workspaces]

The "workspaces" property of the file is an array containing folders of packages to be managed as workspaces from the single, top-level, package

To find more information :

87 questions
19
votes
2 answers

How do I install dependencies for a single package when using npm workspaces?

Using npm workspaces I have a folder structure like this +-- package.json +-- package-lock.json +-- client | `-- package.json +-- shared | `-- package.json `-- server `-- package.json Normally when creating a production build for a nodejs…
joshhunt
  • 5,197
  • 4
  • 37
  • 60
16
votes
3 answers

NPM Workspaces Typescript unable to find local modules

I have a NodeJS monorepo set up using NPM workspaces and Typescript. It works fine without Typescript, however introducing TS brings some dependency resolving errors with it. Current directory setup: +-- node_modules +-- package.json +--…
Brady Harper
  • 235
  • 1
  • 3
  • 17
14
votes
1 answer

NPM 8 workspaces - Install one package as the dependency for another package in monorepo

Say I have the following structure packages - @my-scope/packageA - @my-scope/packageB - @my-scope/packageC Let's say I want to install packageA as a dependency of packageB. With NPM 8 workspaces I would think this ought to do it: npm install…
Andrew
  • 161
  • 1
  • 6
12
votes
1 answer

Multiple React versions in a monorepo, is it possible?

I have this monorepo, built using npm workspaces: ├─ lib │ └─ Foo └─ src ├─ App └─ Web I want to update Web to React 18 while leaving App at React 17 Currently (and working), my dependencies are: ├─ lib │ └─ Foo ├─ src │ ├─ App │ │ ├─…
tallpaul
  • 1,220
  • 2
  • 13
  • 35
11
votes
1 answer

NPM Workspaces only install root packages

During my CI deployments I want to only install package relavent depancies required for that run. I can do this with npm install --workspace package-name However I have some root level scripts with only a handful of deps in the root package.json,…
Titan
  • 5,567
  • 9
  • 55
  • 90
10
votes
2 answers

How to use Turborepo for an existing react app created with Create React App in order to make it a monorepo?

I have a fun project made with create react app. I want to convert the same application to a browser extension. This idea forces me to make the project a mono repo. Because in both applications, I will use the same components, hooks, providers,…
cooskun
  • 558
  • 1
  • 5
  • 20
8
votes
3 answers

node workspaces — require local package

I am using the workspaces feature of node/npm and the layout is like that: . +-- package.json `-- packages `-- p1 `-- package.json `-- p2 `-- package.json ./package.json { … "workspaces": [ "./packages/*" ], … …
philipp
  • 15,947
  • 15
  • 61
  • 106
7
votes
3 answers

MUI Icons used in shared React component library won't render: Error: Element type is invalid: expected a string or a class/function but got: object

I've created a monorepo with a shared component library, but when I import components from that library that contain a MUI icon from @mui/icons-material I get the following error: Error: Element type is invalid: expected a string (for built-in…
jbaumann
  • 181
  • 6
7
votes
1 answer

"Error: Invalid hook call." when importing React component from shared component library in monorepo (turborepo & npm workspaces)

I've been setting up a monorepo with the goal of creating a shared component library to use for several different Next.js apps (following this example) but whenever I import a component from the shared library I get Unhandled Runtime Error Error:…
7
votes
0 answers

install npm workspace dependencies completely inside workspace

Is it possible to run an npm ci --workspace=[some workspace] command and confine the installed dependencies inside that specific workspace directory, instead of bubbling up the shared ones to the project root node_modules folder? Purpose: I have a…
rubixibuc
  • 7,111
  • 18
  • 59
  • 98
7
votes
1 answer

NPM Workspaces - Some modules installed to local node_modules dir

I use npm workspaces. When I install a package for a workspace using nmp i somepackage -w workspace-a it is placed in to the same directory with the workspace if the installed version is different from root version. I want to move it to a sub dir of…
Stan Mayan
  • 271
  • 4
  • 11
7
votes
2 answers

NPM Workspaces monorepo - share local package's distribution folder as root instead of the entire source files

Using NPM Workspaces, I'm sharing one package (components) with others (webapp1 and webapp2). Something like this: root apps webapp1 webapp2 packages components Everything is working well, but everything inside components,…
Johnny Oshika
  • 54,741
  • 40
  • 181
  • 275
6
votes
3 answers

how to delete all node_modules from all packages in npm 7 workspace monorepo

how can I delete all node_modules folders from all packages in an npm 7 workspace? With Lerna we could just execute lerna clean -y but when migrating to native NPM 7+ workspaces, is there some equivalent?
mesqueeb
  • 5,277
  • 5
  • 44
  • 77
6
votes
2 answers

NPM 7 Workspaces installing multiple versions of react

We have a mono-repo that I'm migrating to npm 7's workspaces. Current folder org: \React - package.json (defines workspaces for \apps and \packages) \apps \someApp - React 17.0.1 (Dependency) \otherApp \packages …
Patrick Dench
  • 813
  • 2
  • 9
  • 27
5
votes
0 answers

Running a root-level npm script in a workspace context

I have a script defined in the root-level package.json: { "workspaces": [ "packages/*" ], "scripts": { "clean": "rm -rf lib dist" }, "private": true } I would like to run this script in the context of the the packages/example…
grimsteel
  • 796
  • 1
  • 17
1
2 3 4 5 6