angular安装完后无法正常执行问题解决。
一、报错问题描述 :
排除 | ss |
---|---|
已经在cmd中安装angular在 | 排除nodojs版本不兼容问题 |
在my-app项目的路径下 进行ng操作 | |
排除全局安装 | 正确配制环境变量 |
. : 无法加载文件 C:\Users\87897\Documents\WindowsPowerShell\profile.ps1,因为在此系统上禁止运行脚本。有关详细信息,请参
阅 https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies。
所在位置 行:1 字符: 3
+ . 'C:\Users\87897\Documents\WindowsPowerShell\profile.ps1'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [],PSSecurityException
问题核心:「因为在此系统上禁止运行脚本。所以是权限问题。
二、问题解决
输入 get-ExecutionPolicy 输出 Restricted,执行权限受限。
PowerShell内:
1 检测权限
PS C:\Windows\system32> get-ExecutionPolicy
Restricted
2 set-ExecutionPolicy RemoteSigned 执行策略更改 Y
PS C:\Windows\system32> set-ExecutionPolicy RemoteSigned
执行策略更改
执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如
https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies
帮助主题所述。是否要更改执行策略?
[Y] 是(Y) [A] 全是(A) [N] 否(N) [L] 全否(L) [S] 暂停(S) [?] 帮助 (默认值为“N”): Y
PS C:\Windows\system32> get-ExecutionPolicy
RemoteSigned
PS。选Y,因为选A可能会是以下结果:
注意:set-ExecutionPolicy RemoteSigned 执行策略更改 执行策略可帮助你防止执行不信任的脚本。更改执行策略可能会产生安全风险,如
https:/go.microsoft.com/fwlink/?LinkID=135170 中的 about_Execution_Policies
帮助主题所述。是否要更改执行策略?
[Y] 是(Y) [A] 全是(A) [N] 否(N) [L] 全否(L) [S] 暂停(S) [?] 帮助 (默认值为“N”): A
PS C:\Windows\system32> get-ExecutionPolic
get-ExecutionPolic : 无法将“get-ExecutionPolic”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检
查名称的拼写,如果包括路径,请确保路径正确,然后再试一次。
所在位置 行:1 字符: 1
+ get-ExecutionPolic
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (get-ExecutionPolic:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
3 再次查看 get-ExecutionPolicy
get-ExecutionPolicy
>>> RemoteSigned
4 angular检查 不要ng --version 而是 ng version
PS C:\Windows\system32> ng --version
Error: You need to specify a command before moving on. Use '--help' to view the available commands.
PS C:\Windows\system32> ng version
>>
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 16.2.7
Node: 18.10.0
Package Manager: npm 8.19.2
OS: win32 x64
Angular:
...
Package Version
------------------------------------------------------
@angular-devkit/architect 0.1602.7 (cli-only)
@angular-devkit/core 16.2.7 (cli-only)
@angular-devkit/schematics 16.2.7 (cli-only)
@schematics/angular 16.2.7 (cli-only)
PS C:\Windows\system32>
4 vscode内: 创建项目 ng new 并在项目目录内 ng serve启动服务器
S C:\your-app> ng serve
? Would you like to share pseudonymous usage data about this project
with the Angular Team
at Google under Google's Privacy Policy at
https://policies.google.com/privacy. For more
details and how to change this setting, see
https://angular.io/analytics. Yes
Thank you for sharing pseudonymous usage data. Should you change your mind, the following
command will disable this feature entirely:
ng analytics disable
Global setting: enabled
Local setting: enabled
Effective status: enabled
✔ Browser application bundle generation complete.
Initial Chunk Files | Names | Raw Size
vendor.js | vendor | 2.35 MB |
polyfills.js | polyfills | 333.17 kB |
styles.css, styles.js | styles | 230.91 kB |
main.js | main | 48.32 kB |
runtime.js | runtime | 6.51 kB |
| Initial Total | 2.95 MB
Build at: 2023-10-20T04:41:39.149Z - Hash: 718220da3b24817a - Time: 40499ms
** Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ **
√ Compiled successfully.