nft icon indicating copy to clipboard operation
nft copied to clipboard

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

Open mschipperheyn opened this issue 3 years ago • 1 comments

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.

mschipperheyn avatar Aug 10 '22 11:08 mschipperheyn

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.

styfle avatar Aug 10 '22 19:08 styfle