Requiring files that exist outside of the webpack root directory

Hello. I’m trying to write a webpack application that acts on a set of files that exist just outside of the directory where webpack lives. For example one of the require statements in ‘index.js’ webpack entry script refers to ‘../config.json’. Doing that gives me an error similar to the following:

ERROR in ./index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../config.js in /Users/frank-weindel/Documents/Working/Data Transition/Data Schema/webpack
 @ ./index.js 14:0-30

Relative to the webpack root, that file does in fact exist.

I’ve even tried it using absolute paths, but the same error occurs.

The reason I want to do it this is to keep the webpack application logically separated from the data its trying to use. This data (its a JSON schema) should live on its own.

Is this possible with webpack? Or is it purposefully restricting access to files outside its root?

Author: Fantashit

2 thoughts on “Requiring files that exist outside of the webpack root directory

  1. That’s possible. Try running it with --display-error-details to see more information about the error.

    I bet you changed resolve.extensions and forgot to include the empty string ("").

  2. Thanks for replying @sokra. I see. But why would it be looking outside of where I’m even telling it to look? An random invalid package.json in /home/joesmoe/documents/ should not impact whatsoever a webpack project located in /home/joesmoe/documents/repositories/myproject/app/. Wouldn’t you agree?

Comments are closed.