-
Notifications
You must be signed in to change notification settings - Fork 62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doesn't work with yarn workspaces by default #39
Comments
I'm having the same issue so that PR witth moduleDirs will be awesome, I just don't know how @barraq resolved the issue with 2
but is not the most optimal way as @bryzaguy says |
@alexrqs actually I am using this patch for our monorepo at Freeletics. I simply have this configuration:
and it works like a charm ;) actually that was the reason of the patch. |
@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')
})], |
+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:
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. |
hi, may I ask the current state of this issue? any update? |
In case somebody else is having trouble when using lerna or yarn_workspace, I've come across this answer in s.o.. It turns out, webpack-node-externals can "Read the modules from the package.json file instead of the node_modules folder". By obtaining the dependencies via the package.json instead of depending on what's actually inside the node_modules dir, it wouldn't matter if the actual node modules are scoped out of the package when working as with a monorepo with "Yarn Workspaces" or "lerna". Just my two cents (honest and perhaps naive question) wouldn't this be better if defaulted to true? e.g. |
how can I whitelist |
Try:
|
See issue at liady/webpack-node-externals#39 Solution provided athttps://github.com/liady/webpack-node-externals/issues/39#issuecomment-356647854
If you have many packages and you want to query them all, use this: import glob from 'glob';
const externals = glob
.sync('*/node_modules/', { absolute: true, cwd: __dirname })
.map((modulesDir) => nodeExternals({ modulesDir })); |
In version 2, you can now specify |
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/
The text was updated successfully, but these errors were encountered: