I'm trying to convert my webapp from requireJS loader to Webpack. Nearly all of my 3rd-party dependencies work correctly when bundled from /node_modules
. However, there is one specific file that Webpack refuses to load - even though it is able to find another file from the same dependency!
My webpack.config.js looks like this:
{
resolve: {
// Combine 2 root folders for 1st-party sources
roots: [path.resolve(__dirname, "src", "app"), path.resolve(__dirname, "..", "shared", "src", "app")],
// All require/import paths are assumed to start at one of the above roots
preferAbsolute: true,
// Bundle-able node/yarn modules
modules: [path.resolve(__dirname, "node_modules")]
}
}
This is the error that I'm getting:
Module not found: Error: Can't resolve 'accdc/js/modules/calendar_generator'
in '[path to project]\src\app\components\field\date'
The file throwing this error has the following imports:
import AccDc from "accdc/js/Acc.DC.API.U";
import AccDcCalendar from "accdc/js/modules/calendar_generator";
When I comment out the second line, the project builds successfully. The second line is the only problem here.
Here is a screenshot of my node_modules
folder, with the two files referenced in that import.
This is the dependency in question, by the way. Yes, I know it's deprecated. It would just be a big lift to replace it, and we don't have the manpower for that right now.
Has anyone seen a similar situation where Webpack throws this "Module not found" error even though I can see the file in question right there? Is there some kind of tool that could tell me exactly what (absolute) file paths Webpack uses to search for the module?
I ultimately decided to copy the offending file and put in my source folder. Importing the copied file solved the problem. Since the dependency is deprecated, it's unlikely to get updated any time soon so that file should be fine to sit there until such time as we replace the dependency outright.