NativeScript CLI安装失败及卸载、路径问题技术求助
Environment & Preparations
I'm learning NativeScript and have set up the following tools on my Windows 8.1 Pro 64-bit machine (all installed on D drive):
- Node.js
node-v8.11.2-x64 - Visual Studio Code
VSCodeSetup-x64-1.23.1 - Git
Git-2.17.0-64-bit - Android Studio
android-studio-ide-173.4720617-windows
I ran npm install -g nativescript to install NativeScript, but encountered multiple issues.
Encountered Errors
1. Installation Error
When running npm install -g nativescript, I got a stack overflow error:
C:\Users\UserName>npm install -g nativescript nativescript@4.0.1 preuninstall C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript node preuninstall.js Failed to complete all pre-uninstall steps. C:\Users\UserName\AppData\Roaming\npm\tns -> C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\bin\tns C:\Users\UserName\AppData\Roaming\npm\nativescript -> C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\bin\tns > nativescript@4.0.1 postinstall C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript > node postinstall.js RangeError: Maximum call stack size exceeded at normalizeStringWin32 (path.js:33:30) at Object.resolve (path.js:328:20) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:68:14) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:77:24) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:78:17) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:78:17) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:78:17) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:78:17) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:78:17) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:78:17) npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.3 (node_modules\nativescript\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) + nativescript@4.0.1 updated 1 package in 18.244s
2. tns doctor Error
Running tns doctor throws the same stack overflow error:
C:\Users\UserName>tns doctor RangeError: Maximum call stack size exceeded at normalizeStringWin32 (path.js:33:30) at Object.resolve (path.js:328:20) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:68:14) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:77:24) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:78:17) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:78:17) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:78:17) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:78:17) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:78:17) at sync (C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript\node_modules\mkdirp\index.js:78:17)
3. Uninstallation Stuck
When trying to uninstall with npm uninstall -g nativescript, the process gets stuck at the resolveWithNewModule stage:
C:\Users\UserName>npm uninstall -g nativescript [ ................] / loadDep:readdirp: sill resolveWithNewModule xcode@0.8.0 checking installable status
Questions
- How can I fix the NativeScript installation error?
- How can I properly uninstall NativeScript if the npm command gets stuck?
- Where does
npm install -g nativescriptinstall the package by default? Can I install it to the D drive instead?
Answer
Hey there, let's tackle these issues one by one:
1. Fixing the Installation Error
That stack overflow error comes from an infinite recursion in the mkdirp module, a dependency of NativeScript 4.0.1. This is almost certainly a compatibility issue between your Node.js v8.11.2 and the specific version of mkdirp used here. Here's what to do:
- First, clear the npm cache forcefully to get rid of any corrupted cached files:
npm cache clean --force - Next, manually remove the partially installed NativeScript files:
- Delete the folder
C:\Users\UserName\AppData\Roaming\npm\node_modules\nativescript - Delete the command scripts
tns.cmdandnativescript.cmdfromC:\Users\UserName\AppData\Roaming\npm
- Delete the folder
- Upgrade your Node.js version: NativeScript 4.x works best with Node.js 8.x, but v8.11.2 is quite old. Grab the latest maintenance release of Node.js 8.x (v8.17.0) and install it. Restart your command prompt afterwards to ensure the new Node.js version is picked up.
- Reinstall NativeScript: Run the install command again, specifying the version you need:
If you still run into issues, try installing the latest 4.x version or even a more stable 5.x release (if your project allows it).npm install -g nativescript@4.0.1
2. Properly Uninstalling NativeScript When npm Gets Stuck
The npm uninstall command can get stuck due to corrupted dependencies or cache issues. Manual uninstallation is the most reliable way here:
- Interrupt the stuck process: Press
Ctrl + Cin your command prompt to stop the hanging uninstall. - Delete all NativeScript-related files manually:
- Remove the
nativescriptfolder fromC:\Users\UserName\AppData\Roaming\npm\node_modules - Delete
tns.cmd,nativescript.cmd, and their corresponding non-suffixed script files fromC:\Users\UserName\AppData\Roaming\npm - Optional: Clear the npm cache with
npm cache clean --forceto remove any leftover cached data
- Remove the
- Verify the uninstall: Open a new command prompt and run
tns --version. If you get a message saying the command isn't recognized, you're good to go.
3. Default Installation Directory & Installing to D Drive
- Default location: When you use
npm install -g, global packages are installed toC:\Users\UserName\AppData\Roaming\npm\node_modules, and the command-line scripts (liketns) go toC:\Users\UserName\AppData\Roaming\npm. - Installing to D Drive: You can change npm's global installation path to D drive with these steps:
- Create two folders on D drive:
D:\npm\global(for global packages) andD:\npm\cache(for npm cache) - Run these commands to set npm's configuration:
npm config set prefix "D:\npm\global" npm config set cache "D:\npm\cache" - Add
D:\npm\globalto your system'sPathenvironment variable:- Right-click "This PC" → "Properties" → "Advanced system settings" → "Environment Variables"
- In the "System variables" section, find
Path, click "Edit", and addD:\npm\globalto the list
- Restart your command prompt, then run
npm install -g nativescriptagain. The package will now be installed to your D drive location.
- Create two folders on D drive:
内容的提问来源于stack exchange,提问作者learner

