Menu

Module not found in ReactJS

Error

ModuleNotFoundError: Module not found: Error: Can't resolve '../../public/page-data/sq/d/595050432.json' 

Cause

The page or component that we created doesn't have .js extension.

Resolution

Create the file with required extension. e.g. reactPageSample.js

Running scripts is disabled on this system

Cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170

At line:1 char:1

+ gatsby develop

+ ~~~~~~

    + CategoryInfo          : SecurityError: (:) [], PSSecurityException

    + FullyQualifiedErrorId : UnauthorizedAccess



Resolution

Open CMD or PowerShell and execute the below command and provide the appropriate permission.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

Try the new cross-platform PowerShell https://aka.ms/pscore6

PS C:\Users\mohammadr> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

References:

1. https://stackoverflow.com/questions/67150436/cannot-be-loaded-because-running-scripts-is-disabled-on-this-system-for-more-in

How to get query string values in JavaScript?

Using JavaScript now its very easy to get the URL parameters or query parameters or query string using window object. Below is the sample code snippet of reading the URL parameters.

For example we are accessing the below URL where we have two URL parameters present, and we want to read the source and location values from given or any URL.

https://javascript.jorvee.com/geturlparams.html?source=blog&location=javadeveloper

const urlParams = Object.fromEntries(new URLSearchParams(window.location.search).entries());

 

All the URL parameters are now present as an object in urlParams constant. Now to access any url parameter, just access using urlParams.<name of the parameter>. 
e.g. var urlSource = urlParams.source;

Here, source is a url parameter and it will return "blog" as source value.


Learn JavaScript Free | URL parameters and query String
JavaScript