Tag Archives: javascript

[Solved] Input error: this. Getoptions is not a function

Reproduction steps:

1. The project was created using Vue cli

2. Install less4 x, less-loader10.X development dependency

3. After using lang = “less” in the single file Vue component, the compilation error is found, syntax error: typeerror: this getOptions is not a function

Reason: the version of less loader is too high. Uninstall and reinstall

// uninstall less
npm uninstall less-loader
npm uninstall less

// re-install less3.5.0、less-loader7.3.0
npm i -D [email protected]
npm i -D [email protected]

[Solved] Vue route jumps to the same page many times error: Navigationduplicated

Vue route jumps to the same page and reports an error many times. Navigationduplicated

The error report does not affect the program operation, but it is annoying to be popular. It needs to be solved.
the reason for the error report is this$ router. Push returns promise
just like

function push(){
	return new  Promise((resolve,reject)=>{
	})
}

Solution 1: capture success value and error value (treat symptoms but not root causes)

this.$router.push({
          name: "project",
          params: { projectPattern: this.projectPattern },
        },()=>{},()=>{ });

Solution 2: Rewrite push
and use it the same as before

this.$router.push({
          name: "project",
          params: { projectPattern: this.projectPattern },
        });

In router/index JS file, write a process by judging whether there are resolve and reject incoming values

let originPush = VueRouter.prototype.push;
VueRouter.prototype.push = function (location, resolve, reject) {
  if (resolve && reject) {
    originPush.call(this,location,resolve,reject)
  }else{
    originPush.call(this,location,()=>{},()=>{})
  }
}```

[Solved] ajax Error: Uncaught SyntaxError: Unexpected end of JSON input

To record, the Ajax request is as follows:

		let xhr = new XMLHttpRequest();
        xhr.open("get","https://music.kele8.cn/search");
        xhr.send();
       
        xhr.onreadystatechange = function () {
            // Determine when the Ajax status code is 4 
            if (xhr.status==200) {
                // Get the response data from the server side
                let ans = JSON.parse(xhr.responseText);
                console.log(ans);
            }
			else {
				console.log("Request failed");
			}
        }

If you ensure that the data returned in the background is correct, the get request can be opened in the browser address bar to see the data in JSON format, but the console reports an error and the data is also obtained, it may be that you lack a judgment

Look at the following code:

let xhr = new XMLHttpRequest();
xhr.open("get", "https://music.kele8.cn/search?keywords="+str);
xhr.send();
                        
xhr.onreadystatechange = function () {
     if(xhr.readyState == 4) {
            if(xhr.status == 200) {
                let arr = xhr.responseText;
                let ctype = xhr.getAllResponseHeaders("content-type");
                if(ctype.indexOf("json") > -1) {
                         let res = JSON.parse(arr);
                         console.log(res);
                 }
                 else {
                        console.log(arr);
                }
          }
          else {
                reject('Request failed');
          }
      }
}

It seems that you need to judge XHR in the onreadystatechange event If the readyState attribute is not judged, an error will be reported by JSON

[Solved] error: Unexpected console statement (no-console)

Solution:

Modify package Eslintconfig in JSON: “rules”: {} in {}, add a line of code: “no console”: “off”

NPM install after saving

module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: [
    'plugin:vue/essential',
    '@vue/standard'
  ],
  parserOptions: {
    parser: 'babel-eslint'
  },
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ?'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ?'warn' : 'off',
    "no-console":"off"
  }
}

Or directly use:

window.console.log(“…”) (I haven’t tried)

[Solved] layui table org.thymeleaf.exceptions.TemplateInputException: An error happened during template…

The error message is as follows

Reason:
because the expression between [[…]] is considered an inline expression in thymeleaf, rendering error occurs

Solution 1:
change [[]] after cols to [[]]

Solution 2:
in <script type=“text/javascript” > Add th: inline = “None”

<script type="text/javascript" th:inline="none">

[Solved] Angular&CI/CD:Error: initial exceeded maximum budget

During CI/CD process of angular project, the following errors occur:

Warning: initial exceeded maximum budget. Budget 2.00 MB was not met by 3.01 MB with a total of 5.01 MB.
Error: initial exceeded maximum budget. Budget 5.00 MB was not met by 6.83 kB with a total of 5.01 MB.

The packed file is too large for the specified file size

Solution: modify the angular in the project JSON configuration file (memory parameters)

 "budgets": [{
                  "type": "initial",
                  "maximumWarning": "2mb",
                  "maximumError": "6mb"
                },
              ]

I originally set the maximum error to 5MB, but now I can set it to 6MB. The specific problem depends on the situation

[Solved] Node.js v17 npm run dev Error: opensslErrorStack

Node.js 17 version opensslErrorStack: [ ‘error:03000086:digital envelope routines::initialization error’ ]
Error Messages:

D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui>npm run dev

> [email protected] dev
> vue-cli-service serve

 INFO  Starting development server...
10% building 2/5 modules 3 active ...ader\index.js??ref--13-0!D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\src\main.jsError: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at module.exports (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:417:16)
    at handleParseError (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:471:10)
    at D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:503:5
    at D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:358:12
    at D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
    at iterateNormalLoaders (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:221:10)
    at D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:236:3
    at runSyncOrAsync (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:130:11)
    at iterateNormalLoaders (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:232:2)
    at Array.<anonymous> (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
    at Storage.finished (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
    at D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
node:internal/crypto/hash:67
  this[kHandle] = new _Hash(algorithm, xofLen);
                  ^

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:67:19)
    at Object.createHash (node:crypto:130:10)
    at module.exports (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\util\createHash.js:135:53)
    at NormalModule._initBuildHash (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:417:16)
    at handleParseError (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:471:10)
    at D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:503:5
    at D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\webpack\lib\NormalModule.js:358:12
    at D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:373:3
    at iterateNormalLoaders (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:214:10)
    at Array.<anonymous> (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\loader-runner\lib\LoaderRunner.js:205:4)
    at Storage.finished (D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:55:16)
    at D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\enhanced-resolve\lib\CachedInputFileSystem.js:91:9
    at D:\workspace\ideaproject\RuoYi-Cloud\ruoyi-ui\node_modules\graceful-fs\graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Node.js v17.1.0

Solution:

The reason for the problem is that OpenSSL has been updated in node.js V17
the solutions are:

1. Solve temporarily and set environment variables

#windows
set NODE_OPTIONS=--openssl-legacy-provider
#linux
export NODE_OPTIONS=--openssl-legacy-provider

2. Lower the version of node.js instead of V17

[Solved] nodejs express Error: MulterError: Unexpected field

Problems encountered when using express to write and upload files

The front-end Axios and the back-end express use the multer middleware. They always report the error of the server 500 when uploading. They repeatedly check the code and check the multer documents, and finally find the problem.

No more nonsense, just go to the code:

Back end:

router.post('/upload',upload.single('img'),function(req,res,next){
    console.log(req.file);
})

front end:

formdata.append('img',imgfile);

here, the name in upload.Single() should be consistent with the field name in the front end formdata

Vue Error: renren-fast-vue execute npm install Error [How to Solve]

Resolution NPM: unable to load file D:\code\Renren fast Vue\node_ modules.bin\npm.ps1

There are four steps

It is forbidden to run scripts on this system, that is, you do not have permission. First use the following command:

get-ExecutionPolicy

If output:

Restricted

The above indicates restricted and the status is prohibited. Then give a permission:

Set-ExecutionPolicy -Scope CurrentUser

Re enter:

RemoteSigned

The above is OK. If you want to verify it, enter get executionpolicy and output remotesigned

==================================================================

Build failed with error code: 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})    
npm ERR! code ELIFECYCLE
npm ERR! [email protected] postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Roaming\npm-cache\_logs\2021-12-03T02_48_23_436Z-debug.log
PS D:\work\guigu\guli-vue\renren-fast-vue> get-ExecutionPolicy
Restricted
PS D:\work\guigu\guli-vue\renren-fast-vue> Set-ExecutionPolicy -Scope CurrentUser

cmdlet Set-ExecutionPolicy in command pipeline location 1
Please provide values for the following parameters:
ExecutionPolicy: RemoteSigned
PS D:\work\guigu\guli-vue\renren-fast-vue> get-ExecutionPolicy
RemoteSigned
PS D:\work\guigu\guli-vue\renren-fast-vue> npm install

Vue init webpack Error: unable to verify the first certificate

When initializing the webpack project with Vue cli, use the following commands:

$ vue init webpack [project-name]

After setting up the agent of NPM and modifying the domestic image warehouse, an error is still reported. The error information is as follows:

$ vue-cli · Failed to download repo vuejs-templates/webpack: unable to verify the first certificate

According to the information, the reason for this problem is that we use the proxy server, so Vue cli cannot verify the proxy server certificate when downloading the webpack template, so this error is reported
to solve this error, one way is to turn off the verification of SSL certificates. However, this method is not valid for everyone, and the following method is only used when your proxy server is trusted:

$ npm config set npm_config_strict_ssl=false

If this method doesn’t work, another way is to use the offline method to initialize the Vue project.

Clone the webpack template project to the local C:\users [username]. Vue Templates folder. If there is no such folder, create one. The folder starting with. Cannot be created in windows. You can use CMD or PowerShell to switch to the C:\users [username]\directory and enter the following command to create the folder:

$ mkdir .vue-templates

The download address of the webpack template is: vuejs templates. Select the required template to clone. I select the complete webpack template here. You can clone the project to the folder we created in the previous step through the following command (provided that git Bash is installed):

$ git clone https://github.com/vuejs-templates/webpack ~/.vue-templates/webpack
    1. If Git is not installed, you can also directly download the project in the form of zip on the GitHub and extract it into. Vue templates. Generally speaking, if the clone speed of Git is too slow, you can also directly download and extract the zip in step 3 in addition to setting the agent… Rerun the command of Vue to initialize the project. Note that the offline mode is
$ vue init webpack [project-name] --offline
$ cd [prject-name]
$ npm run dev

[Solved] VUE D:\project\vueProject\vue-02\src\components\hello.vue 5:5 error Parsing error: x-invalid-end-tag

Vue use failure:

D:\project\vueProject\vue-02\src\components\hello.vue

5:5   error   Parsing error: x-invalid-end-tag   vue/no-parsing-error

Such an error was reported when the slot was introduced. After careful inspection, it was found that the label of the slot was written incorrectly.

It should be the <slot/> slash at the back, and it will return to normal after the change.

<!-- /* html page */ -->
<template>
  <div>
    <!-- slot -->
    </slot>
    <h3>This is a custom component hello</h3>
  </div>

</template>


<!-- /* javaScript */ -->
<script>
  export default {

  }
</script>

<!-- /* css */ -->
<style>

</style>