Dynamically required modules based on path.resolve reference src in build
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.7k
- Forks
- 185
- PR merge metrics
- No merged PRs in 30d
Description
Tested against 11.1.4
I have a monorepo with a server api where some of the files are dynamically sync loaded through require based on variables.
const fileArray = parseDirs(path.resolve('../server/src/modules'));
const modelArray = fileArray.filter(
file => file.endsWith('graphql'),
);
modelArray.map(file => {
const pathArray = file.split('modules/');
const model = require('../modules/' + pathArray[1]);
[...]
});
[..]
const model = require('../modules/' + pathArray[1]);
This works fine in development.
When I build to a server version and removed src directories things start to fail.
Ultimately I see references in the build that reference the original path.resolve('../server/src/modules'). In other words, this is not being processed correctly by webpack. It tries to load from src directories instead of the processed chunks.
Is there a way to resolve this? Please don't say: upgrade to next 12. I've had tons of issues with that, not least of which the obligation to upgrade to async import.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the dynamic require example against the reported 11.1.4 behavior, focusing on the path.resolve('../server/src/modules') and generated build references. Trace how the build handles those dynamic module paths; done means the built server resolves processed chunks rather than the removed src directories.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, webpack
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100