Stuart G
Stuart G

Reputation: 185

Node Module Path Execution Windows 10

$ npm install -g static-server
C:\Users\Stuart's\AppData\Roaming\npm\static-server -> C:\Users\Stuart's\AppData\Roaming\npm\node_modules\static-server\bin\static-server.js
+ [email protected]
added 13 packages from 6 contributors in 1.238s

Stuart's@Stuarts-PC MINGW64 ~/Documents/GitHub/PIES-Network/dapp (master)
$ static-server
module.js:549
    throw err;
    ^

Error: Cannot find module 'C:\c\Users\Stuart's\AppData\Roaming\npm\node_modules\static-server\bin\static-server.js'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:612:3

clearly "C:\c\User.." is not a correct path to my node modules directory. I have checked my local paths and everything looks fine. Any help is appreciated Thanks

Upvotes: 1

Views: 462

Answers (1)

bcperth
bcperth

Reputation: 2291

This looks a lot like you have accidentally created a directory called C:\c\Users\Stuart's\AppData\Roaming\npm wherein is located the file static-server.cmd. You have a path variable pointing there also somehow.

When static-server is invoked control is passed to the static-server.cmd batch file at this incorrect location.

node 'C:\c\Users\Stuart's\AppData\Roaming\npm\node_modules\static-server\bin\static-server.js

But static-server.js is located as per your install at:

C:\Users\Stuart's\AppData\Roaming\npm\node_modules\static-server\bin\static-server.js.

In these circumstances you will get exactly the errors shown.

It could be some variation on this and I am happy to help further, but step 1 is to check above because for sure the incorrect path parameter is being passed to node (which of course load and executes static-server.js).

EDIT: Here are some further tests:

  1. Search for all instances of "static-server" on your hard disc. Trying to do this with Explorer will take a long time. The best and fastest way is to download a tool called UltraSeach.

    Here are the search results from my PC ( I created the extra C:\c directory for test purposes).

enter image description here

  1. Check for multiple versions of static-server.cmd or other executable file of that name.

  2. Using a text editor (like notepad) open each static-server.cmd file and add these ECHO commands at the top (ie before the line staret with @IF EXIST "%~dp0\node.exe" (

    ECHO "File 1 executing"

    ECHO "%~dp0"

    PAUSE

If more than one version put "File 2", "File 3" etc.

  1. Now type static-server at a command prompt and it should Echo the message "File n executing" Echo the directory it is executing from Wait for you to press a key to continue.....

    Note the directory it is executing from (call it \CURRENT say)

  2. You can see from static-server.cmd that it then starts node and tried to execute \CURRENT\node_modules\static-server\bin\static-server.js

    In your case its not finding static-server.js where node expects to find it.

  3. Look back to search results in step 1 and see where static-server.js is actually located. Compare this to where node expects to find it in step 5.

Your problem is either that: The static-server.cmd being executed is located in the wrong place OR static-server.js is located at the wrong place.

  1. Here is an additional test. Open a command window and navigate to the directory which has static-server.js. As per the screen-shot it is at C:\Users\Brendan\AppData\Roaming\npm\node_modules\static-server\bin in my case.

Then type node static-server.js. This bypasses the static-server.cmd file altogether, and should start the server. Worked in my case.

Let me know how you go!

Upvotes: 1

Related Questions