Skip to content

For workerDirectory when using msw in workspace used within a certain npm workspaces. #2065

Answered by kettanaito
k35o asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @k35o.

The msw.workerDirectory must always be specified in the root-level package.json. That's the CWD you have when you run npm install. MSW cannot and mustn't assume workspaces or -w flags.

Here's what you should do instead.

  1. npm i msw@latest -D -w packageA
  2. npx msw init ./packages/packageA --save (from the root).

This will store the public path of your nested package for future MSW updates in the root-level package.json:

// ./package.json
{
  "msw": {
    "workerDirectory": ["./packages/packageA/public"]
  }
}

You can also keep a list of values in case multiple packages in your monorepo need the worker script.

Related materials

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kettanaito
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants