I am facing an issue with a package I am working on, which is structured as follows:
- lib/
-- moduleA/
---- index.js
-- moduleB/
---- index.js
- src/
-- moduleA/
-- moduleB/
The package.json
file specifies:
"main": "./lib"
When trying to import a specific module from this package in another project like so:
import moduleA from '@scope/packageA/moduleA';
I encounter an error message from Webpack:
Module not found: Error: Can't resolve '@scope/packageA/moduleA'
Strangely though, importing directly from lib
works fine:
import moduleA from '@scope/packageA/lib/moduleA;
This raises the question why the Webpack isn't resolving the module as expected based on the package's main
entry and supposed hierarchy flexibility for imports.