DEV Community

Discussion on: ReadFileSync return ENOENT

Collapse
 
richardeschloss profile image
Richard Schloss

In the part where you readFileSync, I would use path.resolve. Same for the part with path.join.

contentBase: path.resolve(__dirname, 'dist'),
key: path.resolve(__dirname, 'rootCA.key'),
cert: path.resolve(__dirname, 'rootCA.cert'),

Also, since you're using relative paths, you'd have to change directories to your dist folder to run your server, but it seems like your source code goes up 2 directories, when your dist would only need to go up one (i.e., ../../ should be ../)

If possible, it may be helpful to use aliases to help with path resolution. See more examples here: webpack.js.org/configuration/resolve/

Collapse
 
itssimondev profile image
Simone Aronica

Hello Richard, thanks for the answer!
So yes, I go up twice because webpack bundles starting from the src file, and since server.js is contained into server, which is contained into root where the certificate is I have to go up twice so that webpack can import it into dist. As you can see from the error I get the key that fails to be imported is has a / before the filename, which means that it gets imported correctly into the dist folder. However I will try tomorrow to use path.resolve as (I hope at least) it might help! So thanks for the tip!