Tag Archives: javascript

[Solved] Vue-cli Create Project Error: ERROR command failed: yarn

Create a project through vue-cli, and the error ERROR command failed: yarn is reported

reason:

Installed yarn package manager When creating a vue project, you choose to use yarn package manager, but when creating a project through vue-cli, you use npm, causing a conflict

Solution:

The path to open the document is:C:\Users\Administrator\.vuerc

Note: If you don’t see it, check the hidden items at the top in Explorer
Open the folder and replace yarn with npm
Solve the problem and recreate the item

[Solved] 1:1 error Component name “Header“ should always be multi-word vue/multi-word

An error occurred while starting the vue project:

1:1 error Component name “Header” should always be multi-word vue/multi-word

The reason is that the nonstandard code (that is, nonstandard naming) is regarded as an error during the syntax check

Solution:

Add the configuration: lintOnSave: false in the vue.config.js file, as follows:

const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false
})

Uncaught URIError: URI malformed [How to Solve]

Uncaught URIError: URI malformed

  • url, pass the value, if the key has Chinese characters inside, the browser will be encoded off by default, so this page needs to be decoded first when calling the query interface), the above error occurs.
  • Because the url contains the “%” character, the browser will give an error when it executes decodeURIComponent on “%”.

Repeat the problem

The browser url on the splice on (?q=%好的);

https://www.baidu.com/?q=%好的

Enter the code;

location.search
'?q=%%E5%A5%BD%E7%9A%84'
decodeURIComponent('%%E5%A5%BD%E7%9A%84');

Solution

urlStr.replace(/%/g, '%25');

Fundamentally solve the problem: encode the URL before uploading the value

encodeURIComponent('%好的');
'%25%E5%A5%BD%E7%9A%84'
https://www.baidu.com/?q=%25%E5%A5%BD%E7%9A%84

Error in nextTick: “TypeError: Cannot set properties of undefined (setting ‘checked‘)“

Error in nextTick: “TypeError: Cannot set properties of undefined (setting ‘checked‘)“

When you see nextTick, do you think of $nextTick?

This is exactly the kind of error that needs to be solved by using $nextTick

Vue performs asynchronously when updating the DOM. As soon as a data change is heard, Vue will open a queue and buffer all the data changes that occur in the same event loop, which means that a value assigned by vue will not take effect immediately, but will be updated when the next event is triggered. callback)

$nextTick is a delayed callback that is executed after the next DOM update loop. If you use $nextTick after modifying the data, you can get the updated DOM in the callback

[Solved] Error in event handler for “el.form.blur“: “RangeError: Maximum call stack size exceeded“

The following errors were encountered during form verification; This error will be reported when you lose focus or click to verify

If you look at the examples in the ElementUI document, you will find that they implement custom rules, setTimeout is used to limit the number of times the rules are called. In your case, once the field has a value (ergo, if is false), your else block will be executed again and again until it exceeds the maximum call stack size. You can solve this problem by restricting calls to custom rules

From: Javascript – understanding why element UI event handlers are triggering rangeerror: maximum call stack size exceeded- Stack Overflow

npm install error code EINTEGRITY sha1 [How to Solve]

npm install error code EINTEGRITY sha1

when other environment codes are packaged into another environment, the NPM install installation dependency reports an error.

13023 error code EINTEGRITY
13024 error sha1-LgxPksfBBzrHtltHrDbWAuirTr8= integrity checksum failed when using sha1: wanted sha1-LgxPksfBBzrHtltHrDbWAuirTr8= but got sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA== sha1-stEE/g2Psnz54KHNqCYt04M8bKs=.

Solution:

rm -rf node_modules package-lock.json
npm cache clean --force
npm install --verbose

[Solved] Node Create Express Project Error: Failed to lookup view “error“ in views directory

Node create new Express project prompt an error: Failed to lookup view "error" in views directory

1. Use the EJS engine mode to report an error prompt FaiLED to lookup View “ERROR” in Views Directory

2. Solution
Add error.ejs to Views

<h1><%= message %></h1>
<h2><%= error.status %></h2>
<pre><%= error.stack %></pre>

3. ejstemplate engine needs to be supplemented

ERROR Error: [@ant-design/icons-angular]:the icon XXX does not exist or is not registered.

Error Message:

ERROR Error: [@ant-design/icons-angular]:the icon XXX does not exist or is not registered.

 

Solution:

Adding startup services
nz-icon-register.service.ts

import { APP_INITIALIZER, Injectable } from '@angular/core';
import { NzIconService } from 'ng-zorro-antd/icon';

export const SvgIcons = [
    // nzType='plus'
    {
        namespace: 'nz:plus',
        literal: '<svg viewBox="64 64 896 896" focusable="false" fill="currentColor" width="1em" height="1em" data-icon="plus" aria-hidden="true"><defs><style></style></defs><path d="M482 152h60q8 0 8 8v704q0 8-8 8h-60q-8 0-8-8V160q0-8 8-8z"></path><path d="M176 474h672q8 0 8 8v60q0 8-8 8H176q-8 0-8-8v-60q0-8 8-8z"></path></svg>',
    },
];

@Injectable({
    providedIn: 'root'
})
export class NzIconRegisterService {

    constructor(
        private nzIconService: NzIconService,
    ) { }

    registeIcons(): void {
        SvgIcons.forEach(icons => {
            this.nzIconService.addIconLiteral(icons.namespace, icons.literal);
        })
    }
}

function factory(service: NzIconRegisterService ) {
    return () => service.registeIcons(); 
}

export const ICON_REGISTER_PROVIDES = [
    NzIconRegisterService ,
    {
        provide: APP_INITIALIZER,
        useFactory: factory,
        deps: [ NzIconRegisterService ],
        multi: true,
    }
];

Add the startup service to the startup item
app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { ICON_REGISTER_PROVIDES } from '@core/services/nz-icon-register.service';

@NgModule({
  declarations: [AppComponent],

  imports: [
    AppRoutingModule,
    BrowserModule,
    HttpClientModule,
    // ...other modules
  ],
  providers: [
    ICON_REGISTER_PROVIDES,
  ],
  bootstrap: [AppComponent],
})
export class AppModule {}

[Solved] error:chunkgroup.addoptions:no option merge strategy for name

“webpack”: “^ 5.72.0” error:

/Users/guojianbo/Documents/xxx/node_modules/webpack/lib/ChunkGroup.js:119
					throw new Error(
					      ^
Error: ChunkGroup.addOptions: No option merge strategy for name
    at Entrypoint.addOptions (/Users/guojianbo/Documents/xxx/node_modules/webpack/lib/ChunkGroup.js:119:12)

Solution:

webpack.config.js
before modification:

module.exports = {
	entry: {
	    'abc-def': "./src/js/abc-def.js",
	    'qwe-rty': "./src/js/qwe-rty.js",
	}
}

After modification

module.exports = {
	entry: {
	    'my-abc-def': "./src/js/abc-def.js",
	    'my-qwe-rty': "./src/js/qwe-rty.js",
	}
}

That is, add a prefix to the entry name to prevent conflicts with the internal chunk names of webpack packages

How to Solve pinia Error in ts File

Use Pinia in ts file report an error:

getActivePinia was called with no active Pinia. Did you forget to install pinia

 

1. Create the store.ts file

import { createPinia } from "pinia";

const store = createPinia();

export { store };

2、 Introduced in main.ts

import { createApp } from "vue";
import "./style.css";
import "./main.css";
import App from "./App.vue";
import ElementPlus from "element-plus";
import Avue from "@smallwei/avue";
import "@smallwei/avue/lib/index.css";
import "@/assets/css/mapbox-gl.css";
import { store } from "@/pinia/index";    // Introduce the created pinia
import router from "@/router/index";
import "element-plus/dist/index.css";

const app = createApp(App);

app.use(router);
app.use(store);  // use pinia
app.use(ElementPlus);
app.use(Avue);
app.mount("#app");

3、 Create your own Pinia file

import { defineStore } from "pinia";

interface State {
  nodeArr: any[] | [];
  stencilLoading: boolean;
  selectNodeId: number;
  lcNodeData: LCDataType | {}
}

const defaultState: State = {
  nodeArr: [], // Node data in the drag and drop bar
  stencilLoading: true, // Loading of the drag bar
  selectNodeId: -1, // The node id of the selected drag bar
  lcNodeData: {}, // The LC data in the selected canvas
};

export const lcDataStore = defineStore("lcData", {
  state: () => {
    return defaultState;
  },
  getters: {},
  actions: {},
});

4、 Using Pinia in the TS file

import { lcDataStore } from "@/pinia/lcAssign";
import { store } from "@/pinia/index";

const lcStore = lcDataStore(store);   // Here you have to pass in the store

// After that, you can use the properties and methods inside the lcStore