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.

Can't find module within modulesDirectories

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:35 (13 by maintainers)

github_iconTop GitHub Comments

13reactions
sokracommented, Feb 29, 2016

It seems that the most correct solution will be to create one more package_modules folder at app root.

yep, that’s the best solution with webpack 1.

with webpack 2 modulesDirectories root and fallback were merged into modules:

    modules: [
      "package_modules",
      "/path/to/app",
      "node_modules"
    ]
5reactions
sokracommented, Mar 7, 2016

add the json-loader

Read more comments on GitHub >

github_iconTop 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 >

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