Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamically required modules based on path.resolve reference src in build #306

Open
mschipperheyn opened this issue Aug 10, 2022 · 1 comment
Labels
question Further information is requested

Comments

@mschipperheyn
Copy link

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.

@styfle styfle added the question Further information is requested label Aug 10, 2022
@styfle
Copy link
Member

styfle commented Aug 10, 2022

Can you provide the steps to reproduce with nft print path/to/file.js or nft build path/to/file.js?

this is not being processed correctly by webpack

This repo @vercel/nft doesn't use webpack.

Please don't say: upgrade to next 12
Next.js 11 doesn't get the latest update from this repo (@vercel/nft). Any changes here would need to go into a new Next.js version and then you would need to upgrade to that version to see the effect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants