- Version: v10.12.0
- Platform: MacOS 10.14 (Darwin)
- Subsystem:
The documentation for createRequireFromPath makes it seem like you can pass a directory to the function, but that will never correctly resolve packages.
Using the following directory structure;
src/
└── utils
└── some-tool.js
The following code will throw a MODULE_NOT_FOUND exception (example from the docs):
const { createRequireFromPath } = require('module');
createRequireFromPath('../src/utils')('some-tool');
However, if we pass a file path we can resolve it just fine.
const { createRequireFromPath } = require('module');
createRequireFromPath('../src/utils/index.js')('some-tool');
Is there a bug here or is the documentation wrong? I'm willing to make a PR to either fix the issue or update the documentation :)