Can't find module within modulesDirectories
See original GitHub issuewebpack 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.
Issue Analytics
- State:
- Created 8 years ago
- Comments:35 (13 by maintainers)
Top Results From Across the Web
node.js cannot find a module in the same folder - Stack Overflow
The module should be in the "node_modules" folder to access it like you have described.
Read more >cannot find module [Node npm Error Solved] - freeCodeCamp
To fix the error, you need to install the package that is absent in your project directory – npm install package-name or yarn...
Read more >Documentation - Module Resolution - TypeScript
Module resolution is the process the compiler uses to figure out what an import refers to. Consider an import statement like import {...
Read more >CommonJS modules | Node.js v19.3.0 Documentation
js starts at the directory of the current module, and adds /node_modules , and attempts to load the module from that location. Node.js...
Read more >Cannot find module error when package directory name ends ...
I'm trying to create an npm package that other Next.js developers can import and use in their codebase. My package is called repro...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
yep, that’s the best solution with webpack 1.
with webpack 2
modulesDirectories
root
andfallback
were merged intomodules
:add the
json-loader