I sent a PR with a repro for this here. Here is a copy of the description:
This branch shows what looks to be a race condition in the loader. The tl;dr is that if we import a module inside some-project/a.js it works, but if we add a second import of the same module inside some-project/b.js (ie. same project, same directory), then the loader claims that the dependency is missing. Kind of surprising that this hasn't come up before, so it may be somewhat edge-casey; maybe it only happens with modules that the bundler is configured to look for in other projects — then module in question here is classnames, for which we have configuration that points to frontend-js-react-web.
Even though it may be edge-casey, it's possible we may run into this often, because classnames is a frequently used React library.
How to run the code
Go to Control Panel → [Some site] → Site Builder → Pages → [Some page] Configure → SEO → Topic "Select"
In the modal that opens, you see the new treeview (although you might need to create some categories in order to actually see anything in side it; ie. Control Panel → [Some site] → Categorization → Categories).
The problem
There are two files that both try to import classNames from 'classnames':
When only one file has this import, everything works. When both files have them, the second one fails with this error:
So it seems like somehow the presence of the first require breaks the second one. Maybe a pending promise is preventing the second require from doing the right thing.
About that module that fails to load: this is the classnames package that we get from frontend-js-react-web (as you can see, the loader is correctly trying to get it from frontend-js-react-web$classnames). The file is definitely there (ie. I can see it inside the frontend-js-react-web/build directory). The treeview is defined in the frontend-taglib module. This is the .npmbundlerrc file from the frontend-taglib module; nothing suspicious in there. The treeview is being used from asset-categories-selector-web. No .npmbundlerrc in that module or anything weird that I can see.
To repro
In this PR I defined a local classNames function inside TreeviewCard.js so that there's only one import and everything works. To actually see the bug you need to comment out that function and uncomment the import instead.
I sent a PR with a repro for this here. Here is a copy of the description:
This branch shows what looks to be a race condition in the loader. The tl;dr is that if we
import
a module insidesome-project/a.js
it works, but if we add a secondimport
of the same module insidesome-project/b.js
(ie. same project, same directory), then the loader claims that the dependency is missing. Kind of surprising that this hasn't come up before, so it may be somewhat edge-casey; maybe it only happens with modules that the bundler is configured to look for in other projects — then module in question here isclassnames
, for which we have configuration that points to frontend-js-react-web.Even though it may be edge-casey, it's possible we may run into this often, because
classnames
is a frequently used React library.How to run the code
The problem
There are two files that both try to
import classNames from 'classnames'
:When only one file has this import, everything works. When both files have them, the second one fails with this error:
So it seems like somehow the presence of the first require breaks the second one. Maybe a pending promise is preventing the second require from doing the right thing.
About that module that fails to load: this is the
classnames
package that we get from frontend-js-react-web (as you can see, the loader is correctly trying to get it fromfrontend-js-react-web$classnames
). The file is definitely there (ie. I can see it inside thefrontend-js-react-web/build
directory). The treeview is defined in the frontend-taglib module. This is the.npmbundlerrc
file from thefrontend-taglib
module; nothing suspicious in there. The treeview is being used from asset-categories-selector-web. No.npmbundlerrc
in that module or anything weird that I can see.To repro
In this PR I defined a local
classNames
function insideTreeviewCard.js
so that there's only one import and everything works. To actually see the bug you need to comment out that function and uncomment theimport
instead.