Tag Archives: javascript

How to Solve VUE Error: Mixed spaces and tabs

Cause of the problem: the project uses eslint specification code, and your code violates the specification

The first scheme (recommended): format the code through the editor and unify the indentation method

The second method: turn off the verification of spaces and tabs by eslin
Vue version 3.0:
1, find build – & gt; webpack.base.config.js。 Comment or remove the reference to eslint loader.

{
      test: /\.(js|vue)$/,
      loader: 'eslint-loader',
      enforce: 'pre',
      include: [resolve('src'), resolve('test')],
      options: {
        formatter: require('eslint-friendly-formatter'),
        emitWarning: !config.dev.showEslintErrorsInOverlay
      }
}

2. Restart the project

Vue 3.0 +:
configure the rules of eslin in package.json. Eslintconfig

 {
      "name": "xxxx",
      "version": "0.1.0",
      "private": true,
      "scripts": {
        "serve": "vue-cli-service serve",
        "build": "vue-cli-service build",
        "lint": "vue-cli-service lint"
      },
      "dependencies": {
        xxx
      },
      "devDependencies": {
       xxx
      },
     
      "eslintConfig": {
        "root": true,
        "env": {
          "node": true
        },
        "extends": [
          "plugin:vue/essential",
          "eslint:recommended"
        ],
        "parserOptions": {
          "parser": "babel-eslint"
        },
        "rules": {
          "no-console": "off",
          "no-debugger": "off",
          "no-mixed-spaces-and-tabs": "off"
        }
     
      },
      "browserslist": [
        "> 1%",
        "last 2 versions",
        "not dead"
      ]
 }

The third other method:
create a vue.config.js

module.exports = {
	lintOnSave:false 
}

The toast light prompt of vant in Vue reports an error

Toast light prompt for using vant component library in Vue

Record the toast light prompt in vant today, and use it according to the methods in the official documents. It can’t be used if an error is found
this is what the document says

Toast.success('success');
Toast.fail('fail');

After referencing vant in main.js, directly call toast to report an error
the actual usage is as follows:

this.$toast.success("success");
this.$toast.fail("fail");

Like calling routing, you need to click this.

Vue Error: component has been registered but not used [Two Methods to Solve]

reason:

eslint the code checks that you registered the component but did not use it, and then reports an error. For example, code:

For example, the file component is registered in Vue , but it is not actually used:

...
  import File from "../../components/file";
  export default {
    components: {Pagination, File},
...

At this time, you can cancel the registration. Of course, sometimes we don’t want to cancel and don’t change the code. There are two solutions:

Method 1:

Modify the package. JSON
in package.JSON , find rules under eslintconfig , and add "Vue/no unused components": "off" 

Method 2:

If there is a eslintrc.JS file in the project, you can add it as well:

rules: {
  "vue/no-unused-components": "off"
}

Either of the two can be used. Restart the project after modification. Note: if both files are modified, the eslintrc.JS file has higher priority.

Front end initialization Vue element admin error [How to Solve]

Problem Description:
the project is downloaded according to Vue element admin. To initialize the project, run the following code:

npm install

The result reported an error:

after nearly a day of trouble, we finally found a solution:

1. Run the prompt code first:

// input commands
npm fund

Then the following dependent reward donation prompt appears

2. Then enter:

npm run dev

Then it finally succeeded

[Solved] Npm -v Error: Cannot find module npm_cli

1. If you download the upgraded node version from the node official website, the package management NPM will be automatically installed

2. If you install the NVM and then upgrade or downgrade the node version, the NPM is not automatically installed at this time   As shown in the figure, my node 12.10.0 is downloaded from the official website and 10.15.3 is managed by NVM. After switching back, the NPM will not report an error

Front end project construction error unexpected character ‘@’ solution

After I imported the CSS file of bootstrap, the following error messages appeared in the construction project:

ERROR in ./src/util/bootstrap/bootstrap.min.css
Module parse failed: D:\eclipseWorkspace\mbos\mbos-portal\webContent\src\util\bootstrap\bootstrap.min.css Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected character '@' (1:0)
    at Parser.pp$4.raise (D:\eclipseWorkspace\mbos\mbos-portal\webContent\node_modules\webpack\node_modules\acorn\dist\acorn.js:2221:15)
    at Parser.pp$7.getTokenFromCode (D:\eclipseWorkspace\mbos\mbos-portal\webContent\node_modules\webpack\node_modules\acorn\dist\acorn.js:2756:10)
    at Parser.pp$7.readToken (D:\eclipseWorkspace\mbos\mbos-portal\webContent\node_modules\webpack\node_modules\acorn\dist\acorn.js:2477:17)
    at Parser.pp$7.nextToken (D:\eclipseWorkspace\mbos\mbos-portal\webContent\node_modules\webpack\node_modules\acorn\dist\acorn.js:2468:15)

The reason is that the CSS file contains the @ symbol, and the configuration file does not specify a loader for the CSS file,

Solution: specify loader for CSS file:


{ 
	test: /\.css$/,
	loader: 'style-loader!css-loader' 
},

(a)’21442;’32771;65306;
styles.css Unexpected character’

An error is reported when the less file is introduced into main.js

Today, in a Vue project, I planned to modify the theme of vant, and then an unexpected error occurred. I introduced the less file into main.js, and an error was reported when the project was started.

After looking for the reason, I didn’t find out. Then I tried on the previous old project. From here, I can know that it must be the reason for the version of something. Finally, I found that it is the scaffolding. The new version of Vue cli has helped us configure the less loader and put it in util.js, We just need to modify the webpack.base.conf.js file under the build file, delete or comment out this code, and the project can run normally.

How to Solve “Vue is not defined” Error

Background there is a problem in the introduction of Axios
code

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'


import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './reset.css'

Vue.config.productionTip = false
Vue.use(ElementUI);
axios.default.baseURL = 'https://www.fastmock.site/mock/ad1bc58516abb5f0f452402035be2443/houtai'
Vue.prototype.$http = axios

This is because the order of the two lines of code is wrong
change to

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './reset.css'
axios.default.baseURL = 'https://www.fastmock.site/mock/ad1bc58516abb5f0f452402035be2443/houtai'
Vue.prototype.$http = axios
Vue.config.productionTip = false
Vue.use(ElementUI);

How to Solve NPM installation -g @view/client Error

Installation problem: NPM install – G @ Vue/cli   Long string error reporting

npm ERR! code 1
npm ERR! path C:\Users\A\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\bufferutil
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp info find Python using Python version 2.7.10 found at "C:\Python27\python.exe"
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS msvs_version not set from command line or npm config
npm ERR! gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
npm ERR! gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details
npm ERR! gyp ERR! find VS looking for Visual Studio 2015
npm ERR! gyp ERR! find VS - not found
npm ERR! gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS You need to install the latest version of Visual Studio
npm ERR! gyp ERR! find VS including the "Desktop development with C++" workload.
npm ERR! gyp ERR! find VS For more information consult the documentation at:
npm ERR! gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
npm ERR! gyp ERR! find VS **************************************************************
npm ERR! gyp ERR! find VS
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: Could not find any Visual Studio installation to use
npm ERR! gyp ERR! stack     at VisualStudioFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:121:47)
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:74:16
npm ERR! gyp ERR! stack     at VisualStudioFinder.findVisualStudio2013 (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:351:14)
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:70:14
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-visualstudio.js:372:16
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:54:7
npm ERR! gyp ERR! stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\util.js:33:16
npm ERR! gyp ERR! stack     at ChildProcess.exithandler (node:child_process:404:5)
npm ERR! gyp ERR! stack     at ChildProcess.emit (node:events:394:28)
npm ERR! gyp ERR! stack     at maybeClose (node:internal/child_process:1064:16)
npm ERR! gyp ERR! System Windows_NT 10.0.19042
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd C:\Users\A\AppData\Roaming\npm\node_modules\@vue\cli\node_modules\bufferutil
npm ERR! gyp ERR! node -v v16.7.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\A\AppData\Local\npm-cache\_logs\2021-09-16T09_15_40_144Z-debug.log

the error reporting information found is almost the same, but it is different from mine!

Solution:

1. Find the path of user folder

2. Delete the. Npmrc and. Nrmrc files under the path

  3. Re execute NPM I – G @ Vue/cli — force

–Force force to cover the previous scaffold

  4. Execute Vue – V to check the version

So far, the problem has been solved.

Error message caused by browser plug-in

1. Error description

DevTools failed to load SourceMap: Could not load content for 
chrome-extension://ncennffkjdiamlpmcbajkmaiiiddgioo/js/xl-content.js.map: 
HTTP error: status code 404, net::ERR_UNKNOWN_URL_SCHEME
Unchecked runtime.lastError: The message port closed before a response was received.

2. Cause analysis

It is mainly caused by the use of plug-ins such as oil monkey or Xunlei in Google browser

3. Solutions

Address bar entry chrome://extensions/ , turn off the oil monkey or thunder one by one, if not, F12 – & gt; Settings – & gt; Perferences–> Sources, disable JavaScript maps and CSS maps, clear cache and re access

Node Error: Error: Multipart: Boundary not found [How to Solve]

The front end uses httpclient in the angular library to upload files and set

headers: { ‘Content-Type’: ‘multipart/form-data’ }

When the backend uses featurejs to receive, an error is reported

error: multipart: boundary not found
error reason: multipart does not find the boundary

The uploaded file is a form in multipart/form data format of post request

content-type: multipart/form-data is not followed by the boundary

To sum up, the request header was set many times, overwriting the original form enctype = “multipart/form data”

Conclusion: it is not necessary to set content type: Music/form data repeatedly, otherwise the original may be overwritten and unexpected errors may be caused.


Correct way to get headers:

When uploading formdata type data, you do not need to manually set content typebrowser performance:

it’s done!