Tag Archives: front end

[Solved] HBuilder Error: Cannot read property ‘forceUpdate‘ of undefined

Using the project developed by HBuilderX, WeChat develop tool report an error:

Cannot read property ‘forceUpdate’ of undefined

The solution is shown in the figure:

In the project directory, find manifest.json – WeChat applet configuration – configure “WeChat applet AppID”

Open the developer tool, view the corresponding appid, fill in the upper part, and refresh the developer tool.

If you continue to report this error, restart hbuildx and wechat developer tools after configuration, and re run the project.

 

core-js/modules/es.error.cause.js [How to Solve]

Reason: the installed version of core-js is too old and needs to be replaced with a newer version.

Solution:
1 Delete original version

 npm rm -rf node_modules  

2. install the latest version

npm install core-js@latest

Note:
you cannot directly install a new version. You must first delete the original version dependency, and then install a new version to avoid errors!

[Solved] ERROR in ./node_modules/element-ui/lib/theme-chalk/fonts/element-icons.ttf

Problem Description:

Error reporting of global element introduction in Vue project based on scaffold development

Install according to the official document of element

npm i element-ui -S

Import main.js and use

//Import element

import ElementUI from ‘element-ui’

import ‘element-ui/lib/theme-chalk/index. css’

Vue. use(ElementUI)

Errors are reported as follows

Vscode terminal error


Web page error

Solution:

The problem was eventually found to be that the ‘ ‘ symbol in the font file was not recognized.

The conversion needs to be done with file-loader

Add the configuration to webpack.config.js

{
        test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,
        loader: 'file-loader'
}

Add location as follows

Restart, problem solved

[Solved] gyp ERR! stack Error: Could not find any Python installation to use

Header error prompt

gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | win32 | x64
gyp ERR! find Python
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON

Tail error prompt

gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python="C:\Path\To\python.exe"
gyp ERR! find Python   (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python   npm config set python "C:\Path\To\python.exe"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack     at PythonFinder.fail (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:330:47)
gyp ERR! stack     at PythonFinder.runChecks (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:159:21)
gyp ERR! stack     at PythonFinder.<anonymous> (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:248:16)
gyp ERR! stack     at PythonFinder.execFileCallback (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:294:16)
gyp ERR! stack     at exithandler (node:child_process:406:5)
gyp ERR! stack     at ChildProcess.errorhandler (node:child_process:418:5)
gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
gyp ERR! stack     at onErrorNT (node:internal/child_process:478:16)
gyp ERR! stack     at processTicksAndRejections (node:internal/process/task_queues:83:21)
gyp ERR! System Windows_NT 10.0.22000
gyp ERR! command "D:\\nodejs\\node.exe" "D:\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd G:\aidex\font-end\aidex-ui\node_modules\deasync
gyp ERR! node -v v16.15.1
gyp ERR! node-gyp -v v9.0.0
gyp ERR! not ok

Solution:

NPM installation

npm i -g node-gyp

Yarn installation

yarn global add  node-gyp

 

[Solved] React Startup Error at the First time :SyntaxError: Unexpected token

[react] prompt syntaxerror: unexpected token

1. background

Use react scaffold to build the project

  • Install globally: npm i -g create-react-app
  • create-react-app hello-react
  • Go to the project folder: cd hello-react
  • Start the project: npm start

When executing npm start, an error occurred, please check the node version.

 

2. problem-solving

  • The investigation found that it was caused by the node version.
  • execute node -v ;

  • react-app requires node version greater than 14
  • execute nvm use 14;

  • Just restart.

[Solved] express-jwt Error: Error: jwt is not a function

Problem Description:

Express JWT is not a function

Cause analysis:

The express JWT I installed is version 7.7.5, and the usage has changed.

https://www.npmjs.com/package/express-jwt

Check the official documents for the latest usage

Solution:

1. import

var { expressjwt:jwt } = require("express-jwt")

2. registration

app.use(jwt({ 
secret: 'shhhhhhared-secret', algorithms: ['HS256'] 
}).unless({ path:[/^\/api\//] }))

.unless ({specify the path without access permission with regular})

Or another method, directly add the unique protected path address as a parameter:

app.use("/api", jwt({ 
secret: "shhhhhhared-secret", algorithms: ["HS256"] 
}));

3. user data

Once parsed successfully, the user data contained in the Token will be automatically mounted on req.auth

// This is an API interface with permissions
app.get('/admin/getinfo', function (req, res) {
  // TODO_05: use req.auth to get the user information and use the data property to send the user information to the client
  console.log(req.auth);
  res.send({
    status: 200,
    message: 'User information retrieved successfully! ,
    data: req.auth// the user information to be sent to the client
  })
})

 

[Solved] Error: Node Sass does not yet support your current environment

2022-06-13-node-saas error

System environment

  • node -v v16.15.0
  • node-gyp -v v3.8.0
  • System Darwin 21.3.0

Screenshot of error reporting

The local code execution npm install depends on the installation items. The console displays an error message. The screenshot of the error message is as follows:

Error reporting solution

The project relies on “node-sass”: “^4.12.0”. Replace node-sass with sass

  • implementnode uninstall node-sass
  • Execute node install sass, the installation is successful. The screenshot is as follows:

The project can be started normally, and the interface is as follows:

Error report analysis:

  • The node version is 16.15.0, the system environment is the macOS m1 version, and node-sass has not yet been adapted, so the resulting
  • Replace node-sass with sass

Reference:

https://stackoverflow.com/questions/68095626/node-sass-with-apple-m1-big-sur-and-arm64

[Solved] error TS1086: An accessor cannot be declared in an ambient context

error TS1086: An accessor cannot be declared in an ambient context

Error ts1086 error resolution

After the NPM package is installed, an error is reported when running the project.

The error information is as follows

ERROR in node_modules/xxx/xxx/xxxx.d.ts(15,9): error TS1086: An accessor cannot be declared in an ambient context.

Solution:

Modify tsconfig.json file

{
  "compilerOptions": {
    "skipLibCheck": true
  }
}

JavaScript Common Errors List (Reasons & Solutions)

Here is a list of the most common errors in JavaScript.

 

JavaScript Common Errors List

1.Uncaught TypeError: Cannot read property

Improper initialization of the state when reading the properties of an undefined object or calling its methods or rendering UI components will appear in the console

The simplest Solution: initialize state in the constructor.

2. TypeError: ‘undefined’ is not an object

An error occurred while reading a property or calling a method on an undefined object in safari.

3. TypeError: null is not an object

An error occurred while reading a property or calling a method on an empty object in Safari

Note: in JavaScript, null and undefined are different, which is why we see two different error messages. Undefined is usually a variable that has not been allocated, and null means the value is empty.

4.  (unknown): Script error

This kind of script error occurs when an uncaught JavaScript error (an error caused by the window.oneror handler rather than captured in the try catch) is restricted by the browser’s cross domain policy.

5. TypeError: Object doesn’t support property

The error in ie when calling an undefined method is equivalent to the “typeerror:” undefined “isnotafunction” error in chrome.

6. TypeError: ‘undefined’ is not a function

This is an error in chrome when calling an undefined function.

7. Uncaught RangeError

This error occurs when calling a recursive function that does not terminate, or if you pass a value to a function that is out of range.

8. TypeError: Cannot read property ‘length’

An error occurred while reading the length attribute of an undefined variable.

9. Uncaught TypeError: Cannot set property

When accessing an undefined variable, it always returns undefined. We cannot get or set any undefined properties.

10. ReferenceError: event is not defined

This error is raised when a variable is undefined or is outside the current scope.

[Solved] Vite Error: Failed to load module script: Expected a JavaScript module script but the server…

Error message

Use the white screen of the web page packaged by vite, and the console reports an error.

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of “text/plain”. Strict MIME type checking is enforced for module scripts per HTML spec.

reason

MIME type errors are generally a problem with native windows development. I encountered this after opening it with Python’s built-in http.server on Windows.

Solution

Deploy the packaged files in a formal server environment (such as nginx and Apache)