question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doesn't work with yarn workspaces by default

See original GitHub issue

I have a monorepo which is essentially a repository with many npm packages in it and I just started using yarn workspaces which hoists all dependencies to the root of the repository. I realized that all my node_modules were getting included because they were now located in a node_modules folder two parents up. So I had to switch to externals: /node_modules/

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:41
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

79reactions
chadlycommented, Jan 10, 2018

@barraq you can accomplish the same thing without any code changes to this package by just including multiple instances:

externals: [
  nodeExternals(),
  nodeExternals({
    modulesDir: path.resolve(__dirname, '../../node_modules')
})],
14reactions
atdixoncommented, Feb 22, 2018

+1

Ideally the default modulesDir behavior would be to walk the workspace to its root (consulting all node_modules directories from package to root); thus, webpack-node-externals would work out of the box for monorepos.

There are a few issues with the current solutio of hard-coding module dirs:

  • It is brittle (ie, breaks if a package is moved/copied etc within the monorepo).
  • Options (eg whitelist) have to be repeated for each declaration.
  • Etc.

Also, node itself seems to resolve from node_modules up the directory tree. (I see it do so when I run node scripts that require hoisted libs.) Webpack and other libraries, similarly. So this would be idiomatic, no? If so, perhaps there’s a direct/normalized library/facility for doing this walk that could be leveraged.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Workspaces - Yarn
Workspaces are a new way to set up your package architecture that's available by default starting from Yarn 1.0. It allows you to...
Read more >
Scaling out JavaScript Monorepos with Yarn Workspaces
Bear in mind that, by default, Yarn does zero install setups. That means that all downloaded modules are committed to the remote repository....
Read more >
Working with monorepos - Expo Documentation
In this example, we will set up a monorepo using yarn workspaces without the nohoist option. ... Metro doesn't come with monorepo support...
Read more >
yarn workspaces shared package does not load in create ...
I am using yarn workspaces to maintain my monorepo with this structure: root |- package.json |- packages | - frontend -> create-react-app ...
Read more >
Advanced package manager features for npm, Yarn, and pnpm
npm workspaces; Yarn Berry workspaces; pnpm workspaces ... When using the default configuration, pnpm and Yarn Berry do not use the same ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found