Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

"Path must be a string. Received undefined" #144

Closed
UTGuy opened this issue Dec 28, 2017 · 72 comments
Closed

"Path must be a string. Received undefined" #144

UTGuy opened this issue Dec 28, 2017 · 72 comments

Comments

@UTGuy
Copy link

UTGuy commented Dec 28, 2017

  • npm v5.51
  • node v8.9.0

image

... it seems that anytime I run an npx command it shows "Path must be a string. Received undefined"

@only-cliches
Copy link

only-cliches commented Jan 7, 2018

Also getting this error, it seems like npx isn't able to scan and find already installed packages.

  • Windows 10
  • npm 5.5.1
  • node 8.9.3

@styfle
Copy link

styfle commented Jan 12, 2018

I get the same error on Windows 10.

C:\Users\styfle>node --version
v8.9.4

C:\Users\styfle>npm --version
5.6.0

C:\Users\styfle>npx --version
npx: installed 1 in 2.147s
Path must be a string. Received undefined
9.7.1

@laggingreflex
Copy link

Dupe #148

@denishowe
Copy link

npx.cmd does
CALL "%NODE_EXE%" "%NPX_CLI_JS%" prefix -g
which is
node c:/nodejs/node_modules/npm/bin/npx-cli.js prefix -g
when it looks like it should be doing
npm prefix -g
Where exactly does npx.cmd come from?

@laggingreflex
Copy link

This PR should fix it

@bluelovers
Copy link

The "path" argument must be of type string

@oshingc
Copy link

oshingc commented Feb 20, 2018

I have this issue...

@Sawtaytoes
Copy link

@laggingreflex Looks like the PR failed when run through the CI tool.

@colwilson-mo
Copy link

Windows 10

node -v
v8.9.4

npm -v
5.6.0

npx -v
npx: installed 1 in 2.458s
Path must be a string. Received undefined
9.7.1

@bertday
Copy link

bertday commented Mar 15, 2018

Same issue here.

Windows 7
Node 8.9.4
npm 5.6.0
npx 9.7.1

@Darkle
Copy link

Darkle commented Mar 16, 2018

I'm getting this as well.

Windows 10
Node v8.10.0
npm 5.7.1
npx 9.7.1

@eybbus
Copy link

eybbus commented Mar 18, 2018

Same issue here.

Windows 10 64 bit
Node 8.9.4
npm 5.6.0
npx 9.7.1

@sandyarmstrong
Copy link

What version will include the fix?

@cekvenich
Copy link

cekvenich commented Mar 26, 2018

Solved in: #168

This issue here #144 should be closed.

@IT0315
Copy link

IT0315 commented Mar 30, 2018

webpack/webpack#2463

@rich-newman
Copy link

@cekvenich I don't understand how #168 relates to this. Can you explain please? Are you suggesting that remapping the js file extension will fix this (I've tried remapping it to node.exe and it make no difference to this issue)?

@cekvenich
Copy link

Happy to try to help. The reason people all over www get 'Path must be a string' in Windows is because it it not running node, it is running something else.
After windows does some windows update, it breaks things.

So I found that it is not running node as expected. Normally npx does node to run your js.
But sometimes, on windows it runs 'JScript' instead of node.
That is easy to prove, and 168 shows how. The 'path must be a string' error does not come from node.

So now that we know what the exact problem is and we can reproduce it, it should be easier to fix.
Sadly I can't find source code for the npx.cmd.
(also I complained that node org should be doing better testing for windows )

Does that help you @rich-newman ?

@shawwn
Copy link

shawwn commented Apr 28, 2018

I'm getting this issue on npx 9.7.1, windows 10:

image

This is confusing for end users, since I want to rely on npx to start my program.

In general, is there a way to get npx to shut up? I'd prefer a mode that doesn't log anything at all, unless there's an error.

@TotallyInformation
Copy link

I also added the following to #168 - and I don't believe it is "fixed" by that issue. The issue remains.


Given that npx is now distributed with Node.JS, this is a VERY IMPORTANT thing to fix!

I don't pretend to understand all of the technical details but please bear in mind that this - to users - is an npx error, not an npm error. That's because npm works just fine on Windows, npx does not.

I am not trying to be negative. This is a great tool and I want to see it succeed.

@zkat
Copy link
Owner

zkat commented May 3, 2018

This should have been fixed with npm@5.8.0 (if using the bundled npx) and npx@10 (if you're using a standalone npx install). Please don't comment unless you have this bug with one of those versions or later.

@rich-newman
Copy link

@zkat Both the 'recommended' LTS version of node (8.11.1) AND the 'current' version (10.0.0) seem to install npm 5.6.0 currently on Windows, and have the problem. So are you saying we just need to wait for the node team to fix this?

@zkat
Copy link
Owner

zkat commented May 3, 2018

@rich-newman pretty much. They'll eventually get around to upgrading the CLI, when they find the time.

In the meantime, though, you can do npm i -g npx to install the standalone version of npx, which should fix this.

@styfle
Copy link

styfle commented May 3, 2018

npm install -g npm@5.8.0
npm install -g npx@10.0.1

@zkat
Copy link
Owner

zkat commented May 4, 2018

I assume this is fixed since everyone still reporting it is on older versions of npx.

Just upgrade, y'all.

@zkat zkat closed this as completed May 4, 2018
@TotallyInformation
Copy link

Thanks for everyone's feedback. However, I would point out that all the excellent suggestions here are workarounds - they are not a solution.

My point is that npx is integrated into Node.JS installations and so that needs to work without user intervention. Applying workarounds often results in long term support issues.

The reason for having an open issue in the npx repo (not just node/npm) is that some users will see this as a problem with npx and should therefore be able to see what the problem is and where the problem comes from.

@FranklinYu
Copy link

@TotallyInformation Then the answer is obvious: don't use npx until you are in a Node.js release with fixed version of NPX. Regard this as something you pay for cutting-edge technology; Node.js 8 was simply not yet ready for npx. I would prefer wait until Node.js 10 LTS.

Or if you know some one in Microsoft, tell them that the %PATH% rule is really annoying. That helps everyone, not just Node.js users. It's easy and typical for Linux user to upgrade their global NPM; that shoouldn't be an issue. I believe it's the environment variable rule in Windows that truly annoys most users.

@Darkle
Copy link

Darkle commented Jun 2, 2018

I wonder if it would be a good idea to have a page on the npm website with some of the info in this issue. There is a page in the getting started section for Linux users about installing npm modules globally here: https://docs.npmjs.com/getting-started/fixing-npm-permissions - although its not exactly the same as the issues in this issue, something similar for Windows might be a good idea.

edit: I just noticed the page now says:

This section does not apply to Microsoft Windows. This chapter will be updated to address Windows in the near future.

so maybe it will be updated with info from here.

@TotallyInformation
Copy link

@FranklinYu - I am not using it. Frankly, I didn't even know about it until someone mentioned it on a blog post. But that doesn't help other people who come across the issue does it. If Node wasn't ready for it, that's fine - after all, I'm not paying for it. However, there needs to be clear information.

I do know lots of people at different levels of Microsoft as it happens. But I'm not sure what you are asking? As far as I can see - and maybe I just don't quite get the issue - there is nothing wrong with the default paths. There is simply an issue with the way that npx is configured when it is installed - presumably from the npm installation? Isn't that all that needs fixing?

@Darkle - Yes, that would be a very good idea.

@FranklinYu
Copy link

@TotallyInformation

there is nothing wrong with the default paths.

There is something wrong with the default paths. I cannot figure out a reason why user path is appended after system path to form the effective path. In any case I would like the power to override the system path, and that power is available on Linux (not familiar with macOS but I believe it should be similar). It is very useful on Linux and I sometimes write my own "shim" script for some system commands, without administrator privilege. I would say that Windows is not designed with multi-user scenarios in mind.

The only thing NPX can do, is to actively find and execute NPM in user path (so bypassing Windows PATH searching mechanism), and more importantly, make Node.js ship that improved version. Otherwise the globally installed NPX will always be hidden by the one that came with Node.js. I believe NPM itself is already doing this for npm.cmd, because even if I explicitly specify the NPM from Node.js, it still uses the one from my home directory.

@TotallyInformation
Copy link

OK, I can see your issue with that. Windows does put system paths first. As I've always used Windows, I guess that is normal to me.

I suspect that the reason for this is security. If you put the user folders first - which are writable by the user of course - then malware could install something with the same name as a file in the system folders.

One of the benefits of using npm is that it adds the local bin folder to the start of the path so that you can run local executables.

I certainly agree that this seems to be an issue that comes from the packaging with npm which itself is packaged with node.js. The actual issue has been fixed, but just needs to be known about until node.js is updated with the fix. I also agree that a test for this should be included in the node and npm packaging tests.

@schontz
Copy link

schontz commented Aug 29, 2018

FYI I am running node 8.11.4, npm 6.4.0, and npx 10.2.0 on Windows 10. I was unable to run npx error free until I did what @magnusriga did to fix the path issues. So it seems this is anything but closed.

@FranklinYu
Copy link

FranklinYu commented Aug 29, 2018

I suspect that the reason for this is security. If you put the user folders first - which are writable by the user of course - then malware could install something with the same name as a file in the system folders.

@TotallyInformation That is false sense of security. If a user downloaded and run malware, and the antivirus did not stop it, he is already screwed. Nothing can help. Most (if not all) ways to prevent this can be bypassed by malware.

And that is not the design goal of this "system and user separation" (like preventing non-admin from modifying system path). The privilege system is designed to prevent malware from one user to harm other users on the same machine. If I share a Windows machine with my classmate, their malware won't affect me, as long as the administrator is doing the right thing.

@aboutqx
Copy link

aboutqx commented Sep 22, 2018

2 years later still get this...

@FranklinYu
Copy link

@aboutqx Read the thread, buddy. It’s already been fixed. Use Node.js 10 if you are in doubt.

@aboutqx
Copy link

aboutqx commented Sep 24, 2018

Ok,i update babel-core,and it works.

@uchikaprojects
Copy link

I am still having the same issue with npx

@FranklinYu
Copy link

@uchikaprojects Read the thread, buddy. It’s already been fixed. Use Node.js 10 if you are in doubt.

I should make this an auto-reply.

@uchikaprojects
Copy link

@FranklinYu Thanks very much, let me check it out

@gangsthub
Copy link

gangsthub commented Dec 17, 2018

Upgrading to Node 10 fixed the issue. Remember to npm ci; as some of your system bindings might fail. 💪

@webworthydesign
Copy link

Just in case this helps someone. I had this error and it was being caused by a typo in Grunt. There is a section where we list the themes we want Grunt to rebuild in our project and one of them was spelled wrong. So it was a silly overlook that ended up being a big headache but in the end an easy fix.

A way to find it is to use the --verbose tag when running a grunt build. Hope that helps someone!

@sathyaprakash94
Copy link

I had the same issue, I resolved by refering the below documentation.
https://reactjs.org/blog/2016/07/22/create-apps-with-no-configuration.html?utm_source=hashnode.com

@praveens96
Copy link

I had the same issue, I resolved by refering the below documentation.
https://reactjs.org/blog/2016/07/22/create-apps-with-no-configuration.html?utm_source=hashnode.com

the link was broken.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests