I’m working on a Next.js project and I’m facing an issue with accessing files outside the .next
directory due to Webpack restrictions. I have a CommandHandler
class that needs to load commands from a directory located at /Users/x/Documents/Development/project/src/lib/service/command/commands
. However, my project structure and Webpack configuration seem to prevent accessing files outside of the .next
directory.
Here’s my current code:
import path from "path"
const commandHandler = new CommandHandler(
path.join(__dirname, "../../../../../../src/lib/service/command/commands"),
uid,
user,
);
When I try to run this, I get the following error:
./src/lib/service/command/CommandHandler.ts
Critical dependency: the request of a dependency is an expression
I understand that Webpack has limitations when it comes to accessing files outside of its build context. How can I structure my project or configure Webpack to allow my CommandHandler
to access the necessary files?
- The command files are crucial and must remain in their current location due to project structure requirements.
- I am open to restructuring my project or adjusting the Webpack configuration if necessary.
How can I configure Webpack or adjust my project setup to allow access to these command files?
Any help or guidance on this issue would be greatly appreciated. Thank you!