npm runs into problem in Windows PowerShell, as long as there exists an auto-run bat file implictly changing PWD.

THIS IS A FALSE POSITIVE. IT WAS NOT NPM! SORRY!

This post was originally named “[errno -4058] When running in Windows 10 PowerShell, npm treats non related neighbour folder named npm@xxxxxx as an impediment. Thus it complains “no such file or directory” in the current folder.”.
But shortly after it was posted, I found out that this was a false positive. It was not npm!


The Update of the Truth

  • I enabled a auto-run .bat file via Windows registry HKEY_CURRENT_USER\Software\Microsoft\Command Processor.
    Thus the %UserProfile%\my-auto-setup.bat runs every time a new console window is opened.

  • Inside the said .bat file, these exists a CD statement to conveniently goto a specific folder. And the said folder happens to be named npm@wulechuan, which looks like special to nodejs npmjs program. But it’s really not. This sign misled me before.

  • The .bat file, althought seems have nothing to do with the PowerShell environment, does have a side effect to PowerShell! When I cded to my vuejs project folder, everything looks find. But when I tried to run npm commands, PowerShell was implictly affected by the auto-run .bat file, thus invisibly cded to the npm@wulechuan folder and then tried to run my desired npm command in the incorrect folder.

    I found out this because I later encountered the same problem even if there wasn’t a folder named npm@xxxxx at all, after I orginal post.

  • When I removed the single line of cd statement inside of the .bat file. Problem disappeared. I mean npmjs commands ran smoothly even inside PowerShell.

It’s reasonable for me to turn off BAT echo temporarily inside the auto-run .bat file. So I had no idea that it gets executed also during the npmjs scripts execution processes.
Later, I deliberately added an echo statement into the said .bat file. Then I saw with my own eyes that the .bat file got run again every time I tried to ran some npm commands, in the PowerShell, but not in the CMD.

Still…

Why didn’t CMD environment get affected? Well, it’s not so important to me.

Sorry again for posting misleading contents before!






-------------------- original opinion below ---------------------------------

The original content below are not all true, especially the conclusion.

The story

I’d like to run npm run serve for a really normal/regular Vuejs project.

When I:

  1. chose the PowerShell over Windows 10 to run my npm commands

  2. cded into the correct project folder

  3. and typed npm run serve.

Then:

  1. npm complained that

    npm ERR! path D:\p\dev\wulechuan\personal\npm@wulechuan\package.json
    npm ERR! code ENOENT
    npm ERR! errno -4058
    npm ERR! syscall open
    npm ERR! enoent ENOENT: no such file or directory, open 
    'D:\p\dev\wulechuan\personal\npm@wulechuan\package.json'
    npm ERR! enoent This is related to npm not being able to find a file.
    npm ERR! enoent
    
    npm ERR! A complete log of this run can be found in:
    npm ERR!     C:\Users\wulechuan\AppData\Roaming\npm-cache\_logs\2019-03-22T16_05_05_860Z-debug.log
    

My setup looks like this

The folder structure looks like this:

d:
  \___ p
       |\___ dev
       |       \___ wulechuan
       |                |\___ personal
-------|---look-here----|----->   |\___ npm@wulechuan
       |                |         |           \___ <...>
       |                |         |
       |                |          \___ web-sundries
-------|---and-here-----|--------------->   |\___ my-lovely-vuejs-project
       |                |                   |
       |                |                    \___ <...>
       |                | 
       |                 \___ served
       |                         \___ <...>
       |
        \___ creative
                 \___ <...>

As we can tell from the folder hierarchy shown above, when we traverse the folder tree, we encounter npm@wulechuan first, and web-sundries\my-lovely-vuejs-project a bit later than that.

The npm might treat the folder whose name starts with npm@ being a very special one. because when I was inside the my-lovely-vuejs-project folder or sub folder of it, and ran any of npm run, npm i or npm run serve, I got unexpected results. Among them:

  • the npm i seemed ok but it actually created a package-json.lock under the totally unrelative npm@wulechuan, instead of the pwd, aka the my-loverly-vuejs-project folder.

  • The npm run print nothing and quit quietly.

  • And the npm run serve, you already knew the story.

This problem issued in no other environments but PowerShell only

Other environments

  • I switched to Windows CMD (DOS like), npm ran smoothly.

  • I switched to Git Bash or Cygwin, npm ran smoothly.

  • I switched back to Windows PowerShell, npm ran unexpectedly.

By the way, is it the Microsoft or the npm group that I shall submit an issue to?
Seriously asking!

Other facts

  • I tried two versions of npm. At first the version was 6.5.0. After some struggling, I updated npm to version 6.9.0 by running npm i -g npm.
    Neither version of npm worked with the present of the npm@wulechuan folder.

Problem can be solved this way (NOT TRUE!)

When I finally doubted the naming of the npm@wulechuan. I tried these:

  1. I renamed the npm@wulechuan into npm_at_wulechuan, problem solved in PowerShell.

  2. I deliberately created a new folder nm@wulechuan (no more letter p), npm ran smoothly in PowerShell.

    Note that this new and empty folder is still at a precedent place of the traverse.

  3. I deliberately renamed the nm@wulechaun into npm@wulechuan, problem raised again in PowerShell.

Personally, if npm@xxxxx is not a reserved naming space, I do not want to rename my folder into something else. Obviously I’m forced to do so now.:cry:

Thanks for the update. Good debugging trying different shells. Glad you worked it out!

Thanks for your encouragement.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.