Tag Archives: javascript

[Solved] Error:Plugin/Preset files are not allowed to export objects, only functions

There will be such an error when installing the on-demand loading of element UI under the official documentation of Vue.

Error:Plugin/Preset files are not allowed to export objects, only functions

In the official document of element

On demand import

With the help of   Babel plugin component, we can only introduce the required components to reduce the project volume.

First, install the Babel plugin component:

npm install babel-plugin-component -D

Then, change. Babelrc to:

{
  "presets": [["es2015", { "modules": false }]],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

At this time, after the installation and configuration are completed according to the official documents, an error will be reported when NPM run serve is started

Error: Cannot find module 'babel-preset-es2015'

This is due to the lack of Babel preset es2015 dependency

Just install the Babel preset es2015 dependency

npm i babel-preset-es2015 --save

This is OK, but sometimes you will still report an error when you start after installation

Error: Plugin/Preset files are not allowed to export objects, only functions.

I changed the preset in the babel.config.js file in the project     Not used in the official element UI documentation

Es2015, but change the content of babel.config.js to the following:

module.exports = {
  presets: [
    '@vue/cli-plugin-babel/preset',
    ["@babel/preset-env", {
      "useBuiltIns": "entry"
    }]
  ],
  "plugins": [
    [
      "component",
      {
        "libraryName": "element-ui",
        "styleLibraryName": "theme-chalk"
      }
    ]
  ]
}

Then install the dependencies on the command line

npm install --save-dev @babel/preset-env

This solves the error.

[Solved] Vue Error: Duplicate keys detected: ‘74004’. This may cause an update error

Problems and Solutions

This may cause an update error

This error indicates that in your V-for loop, key   The value may be duplicate.

Duplicate key will cause rendering errors.

The reason for the error is that I didn’t add the key attribute at the beginning. The error code fragment is as follows:

<template>
    <vue-aplayer
            :audio="audio"
            :lrc-type="3"
            :fixed='fixed'
            :autoplay='autoplay'
            :order='order'
            :volume='volume'
            :theme='theme'
            :listFolded='listFolded '
    />
</template>


No more errors will be reported after adding key

<template>
    <vue-aplayer
            :audio="audio"
            :lrc-type="3"
            :fixed='fixed'
            :autoplay='autoplay'
            :order='order'
            :volume='volume'
            :theme='theme'
            :listFolded='listFolded '
            :key="audio.name"
    />
</template>


Note: audio attribute is the list I want to traverse, and name is the primary key in my list, so here I take audio. Name as the value of key ,   key must be unique.

Official description

key

Expectation: the special attributes of number | string key are mainly used in Vue’s virtual DOM algorithm to identify vnodes when comparing old and new nodes. If you do not use keys, Vue will use an algorithm that minimizes dynamic elements and tries to modify/reuse elements of the same type in place as much as possible. When using a key, it rearranges the order of elements based on the change of the key, and removes elements that do not exist in the key. Child elements with the same parent element must have a unique key. Duplicate keys can cause rendering errors. The most common use case is the combination of V-for :

<ul>
  <li v-for="item in items" :key="item.id">...</li>
</ul>


It can also be used to force replacement of elements/components rather than reuse it. It may be useful when you encounter the following scenarios:

Completely trigger the life cycle hook of the component to trigger the transition, for example:

<transition>
  <span :key="text">{{ text }}</span>
</transition>


When text changes, <span> is always replaced rather than modified, so a transition is triggered.

Duplicate keys detected: ‘***‘. This may cause an update error

Encountered while developing Vue project    Duplicate keys detected: ’13’. This may cause an update error. This error will not affect the page display, but will always be printed on the console. As shown in the figure  

 

Error reason: the key value set during V-for loop is not unique. As shown in the figure  

Solution

The key that sets the V-for loop is unique. As shown in the figure  

 

 

   

 

Error code 1 error resolution (NPX create react app my app execution reports an error)

npm ERR! code 1
npm ERR! path /Volumes/D/HTML/vscodework/react/my-app/node_modules/canvas
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! Package pangocairo was not found in the pkg-config search path.
npm ERR! Perhaps you should add the directory containing `pangocairo.pc'
npm ERR! to the PKG_CONFIG_PATH environment variable
npm ERR! No package 'pangocairo' found
npm ERR! gyp: Call to 'pkg-config pangocairo --libs' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (/Volumes/D/HTML/vscodework/react/my-app/node_modules/node-gyp/lib/configure.js:351:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:400:28)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
npm ERR! gyp ERR! System Darwin 20.6.0
npm ERR! gyp ERR! command "/usr/local/bin/node" "/Volumes/D/HTML/vscodework/react/my-app/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Volumes/D/HTML/vscodework/react/my-app/node_modules/canvas
npm ERR! gyp ERR! node -v v14.17.5
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:

Problem solving: install dependent Libraries

brew install pkg-config cairo pango

Check the functions of these databases:

PKG config: used to return installation library information

Cairo: a free drawing library

Pango: a free function library

I don’t know what to do after checking. It’s good anyway!

[Solved] Project Package Error: Javascript heap out of memory

Project package error:JavaScript heap out of memory
1、Modify package.json add –max_old_space_size=8192

"pro": "cross-env NODE_ENV=production node --max_old_space_size=8192 ./dist/server/server.js",

2. Execute increase memory limit


// global install
npm i -g increase-memory-limit

// into the project
increase-memory-limit

Error JavaScript heap out of memory means that the JavaScript heap is out of memory. JavaScript here refers to node. We all know that node is based on V8 engine. In general back-end development languages, there are no restrictions on the use of basic memory. However, when using memory through JavaScript in node, only part of the memory can be used (about 1.4 GB in 64 bit system and about 0.7 GB in 32-bit system). If the front-end project is too large, webpack compilation will occupy a lot of system resources. When it exceeds the default memory limit of V8 for node, memory leakage will occur.

[Solved] JS Error: Uncaught SyntaxError: Illegal return statement

let arr = ['a','b','c']
      for( let i=0;i<=arr.length;i++){
        if (i ==2 ){
          console.log(arr[i])
          return  // error: Uncaught SyntaxError: Illegal return statementcan only be used in functions
        } 
      }

Return can only be used in functions

function run() {
  let a = 1
  if (a == 1) {
    return
  }
  console.log(2); // will not output, return interrupts the execution of the code that follows
}

[Solved] Git submits locally to the remote warehouse Error: failed to push some refs to…

Today, a new project was created locally and a warehouse was built on the code cloud. You want to push it to the code cloud locally, but git push - U origin master , an error is reported:

 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/xxx/app.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

After searching, use: git pull -- rebase origin master to solve the difference between
rebase and merge:

rebase puts the commit from your current branch at the end of the public branch, so it's called a rebase.
merge merges the public branch with your current commit to form a new commit

JS uses the and or operator, and an error is reported: uncaught rangeerror: maximum call stack size exceeded

The or operator is used when the routing guard of the Vue item is in progress,

router.beforeEach((to,from,next) => {
  store.commit('cookie/getToken')
  let token = store.state.cookie.token
  if(!token && to.name === 'PersonalHome'||'Edit'||'EditBlog'||'EditDraft') {
      next('login')
  } else {
      next()
  }
})

Browser error:

solution:
wrap or calculate with ()

if(!token && to.name === ('PersonalHome'||'Edit'||'EditBlog'||'EditDraft')) {
      next('login')
  } else {
      next()
  }

Processing method of eslint verification error

Processing method of eslint verification error

When encountering the eslint verification rule, the following errors or warnings are reported:

1. When encountering no unused vars, no unused expressions, no undef, no restricted globals and other errors, you can verify that the function is turned off by configuring the rules in eslint
2. If there are too many errors and warnings when encountering a file (such as the imported plug-in min.js), you can create it in the root file = & gt Eslintcore (don’t forget the previous point) and configure it, as shown in the following figure:
/SRC/view = & gt; The view file under SRC file ignores the verification
[ Insert picture description here]( https://img-blog.csdnimg.cn/49aecec84d054cc5a2e4eae7fe6fbbda.png#pic_ center

1. If eslint is configured in a separate file

Configure the required verification rules in the created. Eslintrc.js, as shown in the following figure:

2. Referenced scaffolds, such as create react app

Configure verification rules in package.json:

Vue console reports an error duplicate keys detected: ‘XXXX’. This may cause an update error. Solution

Q: the Vue console reports an error duplicate keys detected: ‘XXXX’. This may cause an update error. Solution

Analysis: duplicate key: ‘0’. 0 ‘may cause an update error; This problem usually occurs because there are multiple V-for loops on the same page, and the key of the loop is index. You can define the key as a unique value, such as code or ID. this can be solved
A: the value of the drop-down box must be unique. Check the value of the drop-down box

Ts-node Error: return new TSError(diagnosticText, diagnosticCodes);

TS node can help us run the TS code without manually converting it into a JS file

But we passed

npm install -g typescript
npm install -g ts-node

After installing the two packages, running the file with the TS node command may report an error and cannot be executed

At this time, we need to install one more dependency package

npm install -D tslib @types/node

Just run it with TS node