You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was expecting to be able to set a root to /absolute-path/etc/src and have webpack use that as the base to search for web_modules and node_modules. But instead I had to do either:
resolve.root is usually the root of your project. All paths in the sourcemap for example will be relative to this root. modulesDirectories describes the names of directories for modules which are resolved via node's resolving algorithm. So modulesDirectories shouldn't contain whole paths, but only dir names.
For example if you specifiy ["node_modules", "bower_components"] and require a module a in foo/bar webpack will look them up in this order
foo/bar/node_modules/a
foo/bar/bower_components/a
foo/node_modules/a
foo/bower_components/a
node_modules/a
bower_components/a
Reacted by enes sönmez, Yangshun Tay, Tony Vongprachanh, qqqqqqqqqq, Drew Wells, CHEN HUI, Esen Sagynov, Sunny Wang, Erick-Ismael-Lopez-Ferrari and Glenn 'devalias' Grant
resolve.root is usually the root of your project. All paths in the sourcemap for example will be relative to this root.
You described the context option.
resolve.root is an absolute path to a directory containing modules. resolve.moduleDirectories is an relative path to a tree of directories containing modules.
Use resolve.moduleDirectories only for package managers with a depth dependency structure.
In every other case use resolve.root.
Reacted by Vahe Hovhannisyan, ryerh, Ivan Nikolić, Vojtech Jasny, 唐岗, valerio, enes sönmez, Mario Camacho, Tony Vongprachanh, Alexander Akait and 20 more
Mhmmm this config could have an impact on your bundling performance. It causes webpack to prepend ./src to every folder. So when you write require("a") it will try to look up:
How do we do this in webpack 2.1.0-beta.25? It doesnt allow resolveLoader.modulesDirectories
Reacted by Nik Karbaum, laggingreflex, Colin Wirz, Hung V. Nguyen, Aluan Haddad, Shannon Roberts (Beagin), Adam Braimbridge, Daniel Sunnerberg and Soojung Chae
Using webpack 2.1.0-beta.22, I found that webpack appeared to be ignoring my settings in resolve.modulesDirectories and, as far as I could understand, also resolve.root.
As @alex88 suggested, adding a resolve.modules configuration instead of resolve.modulesDirectories and resolve.root allowed me to use paths relative to a root rather than relative to the module (exactly as this StackOverflow poster desired):
resolve: {
modules: ["."]
}
Reacted by Nazim Jamil-Mir, Revan Zhang, Andrey Shcherbinin, Nikolai and Olivier Tassinari
Activity
jhnns commentedon Sep 15, 2014
resolve.rootis usually the root of your project. All paths in the sourcemap for example will be relative to thisroot.modulesDirectoriesdescribes the names of directories for modules which are resolved via node's resolving algorithm. SomodulesDirectoriesshouldn't contain whole paths, but only dir names.For example if you specifiy
["node_modules", "bower_components"]and require a moduleainfoo/barwebpack will look them up in this orderfoo/bar/node_modules/afoo/bar/bower_components/afoo/node_modules/afoo/bower_components/anode_modules/abower_components/asokra commentedon Sep 16, 2014
You described the
contextoption.resolve.rootis an absolute path to a directory containing modules.resolve.moduleDirectoriesis an relative path to a tree of directories containing modules.Use
resolve.moduleDirectoriesonly for package managers with a depth dependency structure.In every other case use
resolve.root.necolas commentedon Sep 16, 2014
Ah thanks! Not sure how I missed that…long days :(
jhnns commentedon Sep 17, 2014
@sokra Thanks for clearification.
So
bower_componentsshould rather be part ofresolve.rootinstead ofmodulesDirectories?sokra commentedon Sep 17, 2014
ehm... yes
patricktargun commentedon Dec 23, 2015
This wasn't working for me:
How should the resolve look to work with both node_modules and everything inside of the public folder?
jhnns commentedon Dec 26, 2015
@targun sorry, that's not enough information to solve your issue. You need to provide us with examples, your folder structure, your specific error.
patricktargun commentedon Dec 28, 2015
Sorry for the lack of details. This is what ended up working for me:
Now I am able to import files from the root of my src folder rather then needing "../../.."
jhnns commentedon Jan 1, 2016
Mhmmm this config could have an impact on your bundling performance. It causes webpack to prepend
./srcto every folder. So when you writerequire("a")it will try to look up:resolve.rootshould work as expected. I think there is another problem in your config.patricktargun commentedon Jan 2, 2016
Thanks for your help!
soda-x commentedon Sep 22, 2016
@jhnns
So when I write
css!postcss!lesshow to look up postcss-loaderThanks
IAMtheIAM commentedon Sep 26, 2016
How do we do this in webpack 2.1.0-beta.25? It doesnt allow
resolveLoader.modulesDirectoriesalex88 commentedon Oct 14, 2016
@IAMtheIAM use
resolve.modulesdragosrusu commentedon Dec 14, 2016
@alex88 : doesn't seem to work - can you provide a sample?
Tried with: "resolve: { modules: "../devtools/node_modules" } and it did not work out.
evenfrost commentedon Dec 20, 2016
@dragosrusu
resolve.modulesshould be an array, so tryresolve: { modules: ["../devtools/node_modules"] }instead.shirakaba commentedon Jan 16, 2017
Using webpack 2.1.0-beta.22, I found that
webpackappeared to be ignoring my settings inresolve.modulesDirectoriesand, as far as I could understand, alsoresolve.root.As @alex88 suggested, adding a
resolve.modulesconfiguration instead ofresolve.modulesDirectoriesandresolve.rootallowed me to use paths relative to a root rather than relative to the module (exactly as this StackOverflow poster desired):