Skip to main content

Questions tagged [npm-workspaces]

The tag has no usage guidance, but it has a tag wiki.

npm-workspaces
Filter by
Sorted by
Tagged with
23 votes
2 answers
11k views

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 ...
joshhunt's user avatar
  • 5,285
21 votes
3 answers
23k views

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: +...
Brady Harper's user avatar
17 votes
1 answer
10k views

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 ...
Andrew's user avatar
  • 191
16 votes
1 answer
7k views

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 ...
tallpaul's user avatar
  • 1,435
13 votes
1 answer
10k views

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 ...
Stan Mayan's user avatar
12 votes
1 answer
2k views

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 ...
Titan's user avatar
  • 5,846
12 votes
2 answers
9k views

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 ...
cooskun's user avatar
  • 628
11 votes
3 answers
16k views

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 { … &...
philipp's user avatar
  • 16.3k
10 votes
1 answer
11k views

How to specify an npm workspace as a dependency

I can’t find the answer to this seemingly obvious question anywhere. I have some npm workspaces setup in a project. It’s basically a main project with several workspaces within it. They are in a top ...
vy218's user avatar
  • 897
10 votes
3 answers
1k views

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 ...
jbaumann's user avatar
  • 211
9 votes
5 answers
12k views

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 ...
mesqueeb's user avatar
  • 5,998
8 votes
0 answers
1k views

Jest cannot find module in workspace

I have an NPM project structured in workspaces: proj/ +-node_modules/ +-packages/ +-pkg1/ +-src/ |-c1.ts |-c1.test.ts |-package.json |-jest.config.js +-pkg2/ +-src/ ...
Andry's user avatar
  • 16.6k
8 votes
0 answers
3k views

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 ...
rubixibuc's user avatar
  • 7,269
7 votes
5 answers
6k views

List NPM workspaces similar to lerna ls

I'm looking for an NPM command similar to lerna ls that would print out all workspaces. For example, let's say I have package1 and package2 in a packages sub-directory and my package.json looks like ...
restfulhead's user avatar
7 votes
1 answer
2k views

NPM Workspaces with two or more @prisma/client dependencies

I have a monorepo setup. It looks something like this: project node_modules packages my-first-project prisma schema.prisma my-second-project prisma schema.prisma So both projects (my-first-...
pastel-bucket's user avatar
7 votes
2 answers
5k views

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 ...
Johnny Oshika's user avatar
7 votes
1 answer
2k views

Individual package-lock.json for npm workspaces

I have two packages inside my npm workspace api & cdk. I would like to create an individual package-lock.json inside api & cdk as both of those projects will get deployed individually. Is this ...
Jani's user avatar
  • 1,480
7 votes
2 answers
2k views

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 (...
Patrick Dench's user avatar
7 votes
0 answers
3k views

When using npm workspaces, how to force a package to be installed in the relative node_modules?

Here are some related questions: When using yarn workspaces, how to force a package to be installed in the relative node_modules? NPM 7 Workspaces - Multiple node_modules? Should I have to use no-...
TrumanGao's user avatar
7 votes
1 answer
2k views

"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 ...
jbaumann's user avatar
  • 211
6 votes
1 answer
778 views

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" }, ...
grimsteel's user avatar
  • 1,081
6 votes
0 answers
2k views

Different versions of React in an npm workspace

We would like to have a workspace with different versions of react in two npm packages of the same workspace, due to one of them having dependencies not yet compatible with v18. However we're not able ...
jorgen's user avatar
  • 3,543
5 votes
1 answer
2k views

Prepare standalone directory to deploy package in a monorepo using npm workspaces

I have a monorepo that uses npm workspaces. root/ app/ package.json server/ package.json store/ package.json utils/ package.json The app/package.json file references private non-...
Jacob's user avatar
  • 78.5k
5 votes
1 answer
2k views

NPM workspaces with Expo and Typescript

I'm trying to use NPM 7 workspaces within a Typescript Expo project. For now I want to keep the normal Expo structure (with the root App.tsx file), but I want to isolate some parts of the code in ...
Cohars's user avatar
  • 3,942
5 votes
0 answers
197 views

Tell Rollup to also transpile imported typescript packages

I have an npm-workspaces based monorepo with two packages. workspace-a and workspace-b. / - package.json - workspace-a/ - package.json - index.ts - workspace-b/ - package.json - index.ts ...
Loris Sigrist's user avatar
5 votes
0 answers
2k views

Cannot find module 'postcss-preset-env' error using create-react-app inside an npm workspace

I'm trying to add a create-react-app app inside a Turborepo monorepo. Problem is that if I run npm install from the root of the monorepo and then try to start the CRA app by running npm run dev, I get ...
Camilo's user avatar
  • 7,013
5 votes
0 answers
1k views

npm workspace command does not stop executing when command fails for a workspace

I have a bash script that runs test for all workspaces in npm. Here is the bash script: npm ci --no-optional; set -eE; npm run test; #test script in root package.json of workspace Now in root ...
Mandark's user avatar
  • 105
5 votes
0 answers
262 views

Does the "exports" attributes in package.json work in workspaces?

I have a npm package set up as follows project | |-- package.json | |-- workspace_a | |-- package.json | |-- index.js | |-- workspace_b | |-- package.json | | | |-- src | | |-- index.js |...
nickanna_42's user avatar
5 votes
0 answers
735 views

how to use a dependency of multiple major versions in npm 7 workspaces

I have an NPM 7.0 workspaces monorepo. Several of the sub-packages use different major versions of a dependency. However, it seems like NPM workspaces is only able to install a single version and has ...
mesqueeb's user avatar
  • 5,998
4 votes
1 answer
3k views

NPM 7 Workspaces - Multiple node_modules?

I'm having trouble running my app with NPM 7 Workspaces. I am expecting an npm install from the root folder to create a node_modules folder for each of my workspaces, similar to Lerna. However, when I ...
ailish's user avatar
  • 91
4 votes
1 answer
4k views

How to use npm workspace

I develop my app by using npm workspace.but I am totally novice to this concept so that I would like to understand npm workspace behavior . ├── package.json └── packages ├── a │ └── package....
Heisenberg's user avatar
  • 5,129
4 votes
0 answers
746 views

How to import TS from another "NPM-workspace'd" module

Why do I get a syntax error when I try to import typescript from a npm workspace module? I have an app that I've created using 'create-react-app'. Its in a npm package called 'ui'. I wrote some helper ...
kohloth's user avatar
  • 854
4 votes
1 answer
515 views

NPM Workspaces: Share `*.d.ts` TypeScript definition files between workspaces

I have a TypeScript monorepo with NPM Workspaces. There are two packages; A and B. I need type definitions from A inside B. I have added reference to A's definition file in package B's tsconfig.json. ...
curly_brackets's user avatar
3 votes
1 answer
719 views

npm (v7.18.+) install, --workspaces flag needed?

If I have a project with workspaces and use npm install on the root folder, do I need the --workspaces flag to install all workspaces, or is it used automatically? It looks to me like npm install ...
rhhamburg's user avatar
  • 173
3 votes
2 answers
1k views

Build fail in NextJS monorepo — HookWebpackError: processor is not a function

When I try to build one of the NextJS apps in my monorepo, I get the error: $ rm -r packages/library/node_modules/; rm -r packages/daily/node_modules/; rm -r node_modules/; rm -r packages/shared/...
Dauncing's user avatar
  • 127
3 votes
2 answers
3k views

Eslint no-extraneous-dependencies error with npm workspaces

I've set up my monorepo using NPM workspaces with the following high-level structure: root common // Shared package, named @company/common src ... package.json tsconfig.json ...
K Mehta's user avatar
  • 10.5k
3 votes
1 answer
4k views

NPM workspace and VSCode node_modules path

I am using npm workspaces with typescript as specified in this git README https://github.com/Quramy/npm-ts-workspaces-example When I do npm i from the project root directory it installs all packages ...
Pavan Kumar's user avatar
  • 1,837
3 votes
0 answers
535 views

How do I properly structure, configure, and bundle shared code in a Typescript AWS stack monorepo?

I'm having trouble getting my head around how to configure this setup so it bundles, builds, and executes without problems. The crux of the issue lies in how AWS Lambda cannot properly bundle/...
Tsar Bomba's user avatar
  • 1,007
2 votes
2 answers
4k views

How to filter NPM commands to a pattern of workspaces (like filter, include, exclude, glob, grep or subdirectory)?

I'd like to organise a large NPM monorepo such that I can run commands on many (but not all) workspaces according to a category or pattern. This could be by subdirectory, or by a pattern in the ...
user56reinstatemonica8's user avatar
2 votes
1 answer
2k views

Typescript module import - no auto-completion in nested project architecture/npm-workspaces

I have a rather complex setup with many distributed npm packages, which require each other. I tried to break it down as much as possible. The setup looks like this (each subproject having its own ...
StephanB's user avatar
  • 335
2 votes
0 answers
134 views

My .env.local won't load when using an NPM workspace

My root package.json has: { "name": "myapp", "version": "0.1.0", "private": true, "workspaces": [ "packages/common", ...
Shamoon's user avatar
  • 42.8k
2 votes
0 answers
292 views

Install package from package registry instead of local when using NPM workspaces

I'm working on a design system and we are moving from a simple project with all dependencies on the same build step, to a one with a more granular approach, where tokens and icons are separated ...
sebazelonka's user avatar
2 votes
1 answer
595 views

Is there a way to enforce local package dependencies in npm workspaces when publishing packages?

I am trying to use npm workspaces to be able to publish parts of my project as packages: ├── packages │ ├── package-1 │ │ └── package.json │ └── package-2 │ └── package.json ├── src │ └...
tdesero's user avatar
  • 201
2 votes
0 answers
397 views

How to make VS Code go to source instead of dist for workspaces?

I have a monorepo created with NPM workspaces. The structure is as follows: - packages -- common --- src ---- components -- app1 -- app2 common contains some common React components, which both app1 ...
Ronny Efronny's user avatar
2 votes
0 answers
614 views

Npm workspaces and Angular

I'm trying to create a "monorepo" app with npm workspaces (first time I try that) and I have the following (simplified) structure - package.json - tsconfig.json - tsconfig.base.json -- ...
Alexandre Sanigou's user avatar
2 votes
0 answers
160 views

How to deploy npm workspace package separately

There is a project with two registered subprojects pulled into the project by git submodules. When workspaces/submodules are pushed to GitHub it is not possible to install packages without the parent ...
Victor Shelepen's user avatar
2 votes
0 answers
340 views

proper arrangement of npm workspaces and peer dependencies

I built a vue3 component library, which is the root of my folder src/... package.json I added a demo app to the repository that just showcases components and aids in development of components. src/......
stackoverfloweth's user avatar
2 votes
0 answers
937 views

How to cooperatively work on multiple npm packages?

Situation I'm working on a project "main" and in order to split the code and make parts of it reusable, I created 2 npm projects/packages: "A" and "B". "main" ...
CodingKiwi's user avatar
1 vote
2 answers
1k views

Do NPM workspaces make sense for server-side project where all the dependencies needs to be released using CI alongside the server code

NPM can be used for different things front-end projects where the final artifacts often have all their dependencies included. service side services where the node_modules directory is available to ...
rubixibuc's user avatar
  • 7,269
1 vote
1 answer
300 views

How to use published version of a package in an NPM workspace mono-repo

I have a Node Typescript Mono-repo with 2 packages in it. One package is a library which gets published to an npm artifactory. The other package is an express service. I want the service to list the ...
TrollBearPig's user avatar