小绿

小绿

[Solution] Error occurs when running the packaged Vue project

Error:#

PS F:\CODE\Vue\vue-youtube-test> npm install -g serve
changed 89 packages in 6s
PS F:\CODE\Vue\vue-youtube-test> serve -s dist       
serve : Cannot load file F:\Program\nodejs\serve.ps1 because running scripts is disabled on this system. For more information, see https:/go.microsof
t.com/fwlink/?LinkID=135170 about_Execution_Policies.
At line:1 char:1
+ serve -s dist
+ ~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
PS F:\CODE\Vue\vue-youtube-test> 

This error message indicates that the execution policy configuration in your PowerShell environment is preventing the execution of the serve.ps1 script. PowerShell has a security feature called "Execution Policies" to control the execution of PowerShell scripts. This error usually occurs when attempting to run a script, but the system's execution policy is set to block unsigned or unverified scripts from running.


Solution#

  1. Change Execution Policy (recommended for current session only to avoid potential security risks):

    Open a PowerShell window with administrator privileges, then run the following command to temporarily change the execution policy to allow script execution:

    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
    

    This command will only change the execution policy for the current PowerShell session. The policy will reset to default once the window is closed.

  2. Change Execution Policy Globally (not recommended unless you know what you are doing):

    If you need a long-term solution, you can change the global execution policy, but this may increase security risks. Again, open PowerShell with administrator privileges and run:

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
    

    This will allow running local scripts and running signed scripts downloaded from the Internet.


Note#

Changing the execution policy may make your system more vulnerable to malicious scripts. Always ensure that you download scripts from trusted sources and understand the security risks associated with changing the execution policy. If unsure, it is recommended to opt for the temporary solution of changing the execution policy or look for alternative solutions that do not require changing the execution policy.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.