Tag Archives: javascript

[Solved] express-jwt Error: Error: algorithms should be set

When using express JWT, the following errors are reported during compilation:

as a result of:

After JWT is updated on July 7, 2020, the installed express JWT module will default to version 6.0.0. The updated JWT needs to add the algorithms attribute to the configuration, that is, set the algorithm of JWT. Generally, hs256 is the default value for configuring algorithms:

[Solved] fatal error: cuda_runtime.h: No such file or directory

Background

Today, I want to run a yolact model, but in the process of training, I need a DCN network model. This requires CUDA to compile relevant files, but an error is reported. The main errors are:

	cuda_runtime.h: No such file or directory

I spent an afternoon reading a lot of blogs, but I didn’t solve it. Later I knew why. In fact, the solution is also very simple, that is, add some folder paths of CUDA installation directory to environment variables. The following are the solutions for the windows operating system:

Add the following two paths to the environment variable path:

	C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\bin
	C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\lib\x64

Basically, everyone’s default installation path is this. You only need to replace v11.0 according to their installed CUDA version number.

Json.parse: All Error & How to Solve Them

Error Messages:
Uncaught SyntaxError: Unexpected token N in JSON at position 0

JSON.parse(NaN)
JSON.parse('NaN')

Error Messages:
Uncaught SyntaxError: Unexpected token u in JSON at position 0

JSON.parse(undefind)
JSON.parse('undefind')

Error Messages:
Uncaught SyntaxError: Unexpected token o in JSON at position 1

JSON.parse({a:2})

Error Messages:
Uncaught SyntaxError: Unexpected token a in JSON at position 1

JSON.parse('{a:2}')

Error Messages:
Unexpected token ' in JSON at position 1

JSON.parse("{'a':11}")

Error Messages:

JSON.parse('{"a":11}'

**About json.parse

JSON.parseFor parsing JSON string, and returns the corresponding value, which parameters must conform to the format JSON string, otherwise an error.
JSON Is a syntax used to serialize objects, arrays, numbers, strings, Boolean values, and null.
JSON The attribute names of objects and arrays must be strings enclosed in double quotes, and there must be no comma after the last attribute.
JSON The string should also be enclosed in double quotes.
JSON values are forbidden to have leading zeros (JSON.stringify method automatically ignore leading zeros, and the JSON.parse method will report error); if there is a decimal point, then followed by at least one digit.

Vue wran name Error: Unkown custom element [How to Solve]

[Vue warn]: Unknown custom element: – did you register the component correctly? For recursive components, make sure to provide the “name” option.

The Vue project uses ant design. After introducing the spacing space, the name always reports an error. Adding name and modifying name are useless.

Duplicate component names or repeated import. Finally, after searching the configuration file, it is found that it is imported on-demand, and sapce of ant is not introduced. After the introduction, the error report can be solved.

const MyPlugin = {}
import bus from '@cg/bus'
import {
  Result,
  Button,
  Space,
} from 'ant-design-vue'

MyPlugin.install = function (Vue, options) {
  // To reduce the size of the dist, try to do on-demand loading
  Vue.use(Button)
  Vue.use(Form)
  Vue.use(Result)
  Vue.use(Space)
  Vue.use(FormModel)

export default MyPlugin

If there is anything wrong, please correct it and exchange technology together.

Vue Dynamic Display Picture Error 404: Not Found [How to Solve]

<img :src="image"/>

When we dynamically load pictures, an error will appear as shown in the following figure

1. The first possibility is that you write a relative path, and you need to write an absolute path

image:'../assets/image/top10-1.png'
You need to change to the specific path
image:'/src/assets/images/top10-1.png'

2. The second solution is to use require ()

<img :src="require(images)"/>

3. The third solution is to put the pictures under the public directory, but although this solves the problem, the files in this directory will not be packaged when using webpack
4. If you use ts, you cannot use require (). You can use import to import your picture path as a module

<template>
	<img :src="images"/>
</template>
<script>
	import image from '../assets/image/top10-1.png'
	export default{
		data(){
			return {
				images:image
			}
		}
	}
</script>

Vue3 + vite install element-plus error [How to Solve]

Vue3 + vite installation element plus error resolution

1. The console reports an error when running the project

Solution:
1 delete the node_Modules folder and package-lock.json
2 modify package.json
3 modify Vue version number must be above 3.2.2

4 reinstall I, but add – force to force installation, otherwise an error will be reported

 npm i --force

Element plus could not find the problem in index.css

In main.js

Solution:

The solution is also very simple. Now that you have installed the element plus dependency, you can’t find the file. The probability is that the path has changed. So I manually turned to node modules and found that the whole theme chat folder was moved

[Solved] SyntaxError: Cannot use import statement outside a module

Solve the syntaxerror: cannot use import statement outside a module problem

Originally, I wanted to test blob and format in the node environment. After importing relevant JS files, an error cannot use import statement outside a module occurs. Here are the following references to solve the problem:

    1. use commonjs syntax to bypass import
let Blob = require('blob-polyfill/Blob');

It can solve the problem of failed file import at present, but it means that you can’t use import to import in the future. The fundamental problem has not been solved. Of course, this is not my style. Then go to consult the data. What the elder brother said is well summarized as follows:

The error is reported because the node environment does not support ES6 syntax. We can install Babel jest, @Babel/core, @Babel/preset env to solve the problem (these plug-ins can convert ES6 code into Es5 so that the node environment can be recognized. Here I choose @Babel/preset env for installation). After installation, create babel.config.js file in the root log of the project: see the name of this file, Babel is configured; (similar to webpack.Config.JS),

module.exports = {
    "presets": [
        ["@babel/preset-env",
            {
                "targets":
                    { "node": true }
            }
        ]
    ]
}

Generally speaking, package.json is not configured with type, and it is equipped with type: type: "module". The problem is solved here. Finally, I also remembered that when I first used sass, I had to configure it to compile sass into CSS and be recognized by the environment (Longyin).

[Solved] it only responds to error and does not enter success after AJAX is successfully processed

1. Problem description

Front end request code

$.ajax({
    url: 'getOne', 	
    data: {		
        name: 'zhangsan',
        pwd: '123'
    },
    type: 'get',		
    dataType: 'json',	
    success: function (res) { 
        alert("成功" + res)
    },
    error: function (xhr, errorMessage, e) { 
        alert("失败" + errorMessage);
    }
})

Backend servlet code

@WebServlet(name = "getOne", urlPatterns = "/getOne")
public class GetOne extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      	// Set encoding
       response.setContentType("application/json;charset=utf-8");
       // Processing business logic
        
         // Responding to the request, there may be IO exceptions in the way of using the stream, so the exception is caught
        PrintWriter out = response.getWriter();
        try {
            out.write("ajax request successful");
            out.close
        } catch (Exception exception) {
            out.write(exception);
        }
        out.close();
    }
}

Then it is found that after each processing, it will only respond to the abnormal error function and cannot enter success


2. Problem solving

The code above looks OK at first glance. I thought so at first. However, after some analysis, it is found that the format of the return value type at the back end is incorrect

What do you mean?

I set the JSON format in the back-end response

response.setContentType("application/json;charset=utf-8");

However, I output the ordinary string with the stream when responding, not the JSON format string

out.write("ajax request successful");

How to solve it?

Method 1: change the string format to JSON format
back end output: out.Write ("{'data':'ajax request succeeded '}")
front end: alert ("success" + res.data) method 2: change the type of request and processing to text
back end: response.setcontenttype ("application/JSON; charset = UTF-8")
front end: datatype: 'text'