3

I have a repo with the following format:

-> /
   -> client/
   -> server/
      -> package.json
      -> index.js
   -> package.json

In the package.json of the root folder, I have a start script as the following:

"start": "node server/index.js"

In the package.json under the server folder, I have a start script as the following:

"start": "nodemon --exec node index.js"

When I cd into the server folder and run the start command, nothing breaks. But the moment i run the start command from the root level package.json, i get the following error:

internal/fs/utils.js:425
    throw new ERR_INVALID_ARG_TYPE(propName, ['string', 'Buffer', 'URL'], path);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type undefined
    at Object.openSync (fs.js:446:3)
    at Object.readFileSync (fs.js:354:35)
    at Object.<anonymous> (I:\datum_mui\server\index.js:131:13)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:824:10)
    at internal/main/run_main_module.js:17:11
npm ERR! code ELIFECYCLE
npm ERR! errno 1

I am not sure what is causing this. could someone enlighten me about what is happening behind the scenes?

EDIT

I have narrowed down the error to my index.js

 if (nodeEnv === 'local'){
  app.listen(getPort(nodeEnv));
} else{
  https.createServer({
    key: fs.readFileSync(getKeyFilePath(nodeEnv)),
    cert: fs.readFileSync(getCertFilePath(nodeEnv))
  }, app).listen(getPort(nodeEnv));
}

Turns out that the methods getKeyFilePath() and getCertFilePath() returns null and that causes the fs module to trip.

I automatically assume that because there is an if-else statement, I will never encounter such an issue. But it turns out that i will.

Strange though as it works normally when I am in the server folder but when I am outside the server folder this error crops up.

AKJ
  • 749
  • 6
  • 29

0 Answers0