You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NativeScript CLI安装失败及卸载、路径问题技术求助

NativeScript Installation/Uninstallation Issues on Windows 8.1 Pro 64-bit

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

  1. How can I fix the NativeScript installation error?
  2. How can I properly uninstall NativeScript if the npm command gets stuck?
  3. Where does npm install -g nativescript install 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.cmd and nativescript.cmd from C:\Users\UserName\AppData\Roaming\npm
  • 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:
    npm install -g nativescript@4.0.1
    
    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).

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 + C in your command prompt to stop the hanging uninstall.
  • Delete all NativeScript-related files manually:
    • Remove the nativescript folder from C:\Users\UserName\AppData\Roaming\npm\node_modules
    • Delete tns.cmd, nativescript.cmd, and their corresponding non-suffixed script files from C:\Users\UserName\AppData\Roaming\npm
    • Optional: Clear the npm cache with npm cache clean --force to remove any leftover cached data
  • 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 to C:\Users\UserName\AppData\Roaming\npm\node_modules, and the command-line scripts (like tns) go to C:\Users\UserName\AppData\Roaming\npm.
  • Installing to D Drive: You can change npm's global installation path to D drive with these steps:
    1. Create two folders on D drive: D:\npm\global (for global packages) and D:\npm\cache (for npm cache)
    2. Run these commands to set npm's configuration:
      npm config set prefix "D:\npm\global"
      npm config set cache "D:\npm\cache"
      
    3. Add D:\npm\global to your system's Path environment variable:
      • Right-click "This PC" → "Properties" → "Advanced system settings" → "Environment Variables"
      • In the "System variables" section, find Path, click "Edit", and add D:\npm\global to the list
    4. Restart your command prompt, then run npm install -g nativescript again. The package will now be installed to your D drive location.

内容的提问来源于stack exchange,提问作者learner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:19:13