webpack: Can't find module within modulesDirectories
webpack config:
resolve: {
modulesDirectories: [
"package_modules",
"/path/to/app",
"node_modules"
],
]
Option resolve.root
is not defined.
Files tree:
/app
|- lib
| \- index.js
|
\- my_package
|- package_modules
| \- lib
| \- index.js
|
|- subfolder
| \- file_in_subfolder.js
|
\ - file_in_package.js
lib/index:
export const foo = "foo"
;
my_package/package_modules/lib/index:
export const bar = "bar"
;
my_package/file_in_package:
import * as obj from "lib";
console.log("lib in package root:", obj);
my_package/subfolder/file_in_subfolder:
import * as obj from "lib";
console.log("lib in package subfolder:", obj);
In console I have:
> lib in package root: { bar: "bar" }
> lib in package subfolder: { foo: "foo" }
Is it correct? I expected that it will be { bar: "bar" }
in both cases.
Changing import path to lib/index
does not help.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 35 (13 by maintainers)
yep, that’s the best solution with webpack 1.
with webpack 2
modulesDirectories
root
andfallback
were merged intomodules
:add the
json-loader