0

I am using nodejs 11.14.0 (and have tested with other versions too). I have a nodejs script which uses both config.js and require js. The code runs on Windows 10 and most other OS versions of Windows which I need. However, when I try to run the same code which runs on the Windows host OS in a Windows Docker Container (ie as a guest OS), I get the following error-

C:\TEMP\mypwa>node build.js
fullFilename is: C:\TEMP\bundles\com.foo.studio.viz.core.win64\foowebstudio\config\default.js

Loading[config]..C:\TEMP\bundles\com.foo.studio.viz.core.win64\foowebstudio\config\default.js

C:\TEMP\bundles\com.foo.studio.viz.core.win64\foowebstudio\node_modules\config\lib\config.js:928
    throw new Error("Cannot parse config file: '" + fullFilename + "': " + e3);
    ^

Error: Cannot parse config file: 'C:\TEMP\bundles\com.foo.studio.viz.core.win64\foowebstudio\config\default.js': TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at Config.util.parseFile (C:\TEMP\bundles\com.foo.studio.viz.core.win64\foowebstudio\node_modules\config\lib\config.js:928:11)
    at C:\TEMP\bundles\com.foo.studio.viz.core.win64\foowebstudio\node_modules\config\lib\config.js:698:28
    at Array.forEach (<anonymous>)
    at C:\TEMP\bundles\com.foo.studio.viz.core.win64\foowebstudio\node_modules\config\lib\config.js:692:14
    at Array.forEach (<anonymous>)
    at Config.util.loadFileConfigs (C:\TEMP\bundles\com.foo.studio.viz.core.win64\foowebstudio\node_modules\config\lib\config.js:691:13)
    at new Config (C:\TEMP\bundles\com.foo.studio.viz.core.win64\foowebstudio\node_modules\config\lib\config.js:122:27
)
    at Object.<anonymous> (C:\TEMP\bundles\com.foo.studio.viz.core.win64\foowebstudio\node_modules\config\lib\config.js:1752:31)
    at Module._compile (internal/modules/cjs/loader.js:868:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:879:10)

Can you please help me fix this ?

TIA.

ZeroGraviti
  • 1,047
  • 2
  • 12
  • 28

2 Answers2

0

In docker, you may forget to set WORKDIR. So it can't read your config.

enter image description here

I'm using Linux OS so you need convert syntax to window syntax.

Trần Công
  • 288
  • 1
  • 5
  • Thanks for your reply. What should the workdir point to ? App code base or the nodejs install location ? – ZeroGraviti Aug 20 '19 at 18:58
  • Yes, it bases nodejs. My workdir point to the root folder of my project. – Trần Công Aug 21 '19 at 03:44
  • I don't have any issue building the docker image. It's only when I create the container from this image and try to run my nodejs app. I tried setting the WORKDIR but it did not help. I still get the same error – ZeroGraviti Aug 21 '19 at 03:47
  • To add clarity to the issue, I am doing a docker run based on this custom image and when I enter into the running docker container in an interactive session, I manually cd to the workdir and am trying to run the nodejs app. – ZeroGraviti Aug 21 '19 at 04:16
0

There was one missing environment variable which was not being set by default in the Windows docker container. The code needed this and was therefore erroring out with an 'undefined' value. The Windows env var is HOMEPATH.

ZeroGraviti
  • 1,047
  • 2
  • 12
  • 28