AllSolutions
AllSolutions

Reputation: 1266

Node / Electron: Cannot find module '"c:/Program'

While running an Electron application using the script npm run debug, the VSCode terminal throws up the error: Cannot find module '"c:/Program'

It does not even mention the full directory name Program Files and the rest of the path.

The full error stack trace is:

Error: Cannot find module '"c:/Program'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:584:15)
    at Function.Module._load (internal/modules/cjs/loader.js:510:25)
    at Module.require (internal/modules/cjs/loader.js:640:17)
    at Module._preloadModules (internal/modules/cjs/loader.js:809:12)
    at preloadModules (internal/bootstrap/node.js:591:7)
    at startup (internal/bootstrap/node.js:272:9)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:759:3)

What is wrong in my environment and how can I fix it? My OS is Windows 10 and I have nvm installed.

The log file mentions the path as C:\\Users\\MyUserName\\scoop\\apps\\nvm\\current\\nodejs\\nodejs\\node.exe

I suspect it to be some issue with PATH variable or with nvm.

EDIT 1:

After modifying the PATH and inserting quotes around all paths having spaces, the npm run debug started working when run from the integrated terminal. But when I run the same using the VSCode Run and Debug tab, then I still get the same error.

My nvm path is: C:\Users\MyUserName\scoop\persist\nvm

I guess I installed nvm using scoop long ago.

My debug script is:

'npm run dotenv && electron --inspect=5858 ./out/src/main.js'

If I create a separate script with the command npm run dotenv and run it from the UI using the Run and Debug tab, then I am not getting any error.

So I guess the error is in running the electron part of the command.

Upvotes: 0

Views: 440

Answers (1)

Mateo Covacho
Mateo Covacho

Reputation: 90

The issue seems to be that you have a path string with spaces and when node sees that it ignores the part of the directory name after the space.

Try using double quotes when you define the path and use double backlashes when defining the path string

Upvotes: 1

Related Questions