Tag Archives: nodejs

Use of $watch in Vue (solve rangeerror: maximum call stack size exceeded)

Problems encountered:

In a requirement, the change of a form needs a function of history recording. Because the form is very large (it is to edit an article), it is impossible to be specific to a certain attribute, so the method of watch monitoring is adopted, and {deep: true} is set. However, when previewing, I encountered the error of rangeerror: maximum call stack size exceeded . After some investigation, I found that it was caused by watch monitoring, and then I didn’t know what the problem was.

Even if nothing is written in the business code, a simple console.log will not work. As long as deep: true is set, an error will be reported, which is a headache. I didn’t find a similar case on the Internet. I thought again: since the error lies in the watch, can I dynamically monitor and cancel monitoring ?I found the answer on the official website https://cn.vuejs.org/v2/api/#vm -watch

Basic use of $watch (refer to the official website)

VM. $watch (exporfn, callback, [options]) the return value is a {function} unwatch , which returns a function to cancel the observation, which is used to stop the trigger callback option: deep, deep listening option: immediate, whether to execute once immediately

// Key Path
vm.$watch('a.b.c', function (newVal, oldVal) {
  // Do something
})

// function
var unwatch = vm.$watch(
  function () {
    // The expression `this.a + this.b` is called every time a different result is reached
    // the handler function will be called.
    // This is like listening for an undefined computed property
    return this.a + this.b
  },
  function (newVal, oldVal) {
    // Do something
  }
)

// Cancel the listener

unwatch()

My solution, for reference

// Call setWatchChapters when created, call removeWatchChapters in other cases, depending on the business case
export default {
	...
	data () {
		return {
			unWatchChapters: null
		}
	},
	created(){
		this.setWatchChapters()
	},
	methods:{
		setWatchChapters () { // Setting up a listener for chapters
			if (!this.unWatchChapters) { // prevent setting listeners more than once
				setTimeout(() => { // There are still some bugs, so use setTimeout to add to the event queue
					this.unWatchChapters = this.$watch('report.chapters', () => {
						// do something
					}, { deep: true })
				}, 0)
			}
    	},
    	removeWatchChapters () { // Unlisten to chapters
			if (this.unWatchChapters) {
				this.unWatchChapters()
				this.unWatchChapters = null
			}
		}
	}
}

Nodejs: TypeError: The super constructor to “inherits“ must not be null or undefined

Recently, when using statsd, this sentence is util. Inherits (configurator, process. Event emitter); Error: “typeerror: the super constructor to” inherits “must not be null or undefined”

The reason is that there is no event emitter object in process in the newer nodejs version. The solution is to create an event emitter object for process before calling util. Inherits, as follows:

process.EventEmitter = require('events').EventEmitter

[How to Solve] Nodejs: interface error CORS error

Background: local Vue calls local nodejs interface and reports cross domain error.


first, check that nodejs service has been configured: “access control allow origin”, “*”

2、 Check that nodejs service has been configured: “access control allow headers”, “*”

	Access-Control-Allow-Headers Not for the * sign, be careful to check whether the front-end header and the value configured here is consistent, otherwise it will also report cross-domain. In particular, some projects require header pass-through parameters

NPM can’t find D: //nodejs/node all of The solution of sudden_modules/NPM/bin/npm-cli.js

Node installed with NVM

Use very normal, suddenly one day NPM error

npm -v  
NPM does not exist

node -v

Node does not exist

Baidu, very peer will tell you, re install node

If you haven’t changed environment variables and deleted files, you don’t need to

First NVM – V to see if NVM exists

If there is NVM, see if there is a node file

nvm list

 

There is a node, but it can’t be found with noe – V. then the problem is clear. Just NVM use   14.16.1, found in node – V NPM – V. Go to the next event, OK, all right

Node.js operation mysql error Cannot enqueue Handshake after invoking quit

Error Background:
When the database operation is performed for the first time, it is successful. The second time a database operation is performed, an error is reported as shown in the title.
The reason:
This is because after we close the connection with the.end() method, we need to re-call createConnection to recreate a connection.
Solutions:
For example, the following encapsulates a method that operates on database queries and additions. Each time a new connection is created using mysql.createconnection () before the database operation is performed, instead of putting it directly to the outermost layer.

var mysql  = require('mysql');  
exports.find=function(findSql,callback){
    var connection = mysql.createConnection({     
        host     : 'localhost',       
        user     : 'root',              
        password : '123456', 
        port: '3306',                   
        database: 'namesharing',
    });
    connection.connect();
    connection.query(findSql,function (err, result) {
        if(err){
          console.log('[SELECT ERROR] - ',err.message);
          return;
        }
        connection.end();
        callback(result)
    });
}


exports.insert=function(addSql,addSqlParams,callback){
    var connection = mysql.createConnection({     
        host     : 'localhost',       
        user     : 'root',              
        password : '123456',       
        port: '3306',                   
        database: 'namesharing',
    });
    connection.connect();
    connection.query(addSql,addSqlParams,function (err, result) {
        if(err){
            console.log('[INSERT ERROR] - ',err.message);
            return;
        }
        connection.end();
        // console.log('INSERT ID:',result);  
        callback(result)
    });
}

 

NPM install Error cb.apply is not a function

NPM install error cb.apply is not a function

solve:
Win + R open and run, enter % appdata% to delete NPM and NPM cache folder, and execute NPM cache clean — force
At this point, it should be OK. If not, uninstall node.js and install it again.

If not!!

Change yarn

Install yarn NPM install - G yarn

yarn install instead of NPM install

then, everything will be fine

NPM and cnpm installation failure solution

First, post the error: here is my error log:

0 info it worked if it ends with ok
1 verbose cli [ 'D:\\nodejs\\node.exe',
1 verbose cli   'D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install',
1 verbose cli   '-g',
1 verbose cli   'cnpm',
1 verbose cli   '--registry=https://registry.npm.taobao.org' ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session 026191e276c3f621
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 silly fetchPackageMetaData error for cnpm@latest request to https://registry.npm.taobao.org/cnpm failed, reason: connect ETIMEDOUT 93.184.216.34:8080
8 timing stage:rollbackFailedOptional Completed in 1ms
9 timing stage:runTopLevelLifecycles Completed in 133469ms
10 verbose type system
11 verbose stack FetchError: request to https://registry.npm.taobao.org/cnpm failed, reason: connect ETIMEDOUT 93.184.216.34:8080
11 verbose stack     at ClientRequest.req.on.err (D:\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\index.js:68:14)
11 verbose stack     at ClientRequest.emit (events.js:189:13)
11 verbose stack     at onerror (D:\nodejs\node_modules\npm\node_modules\agent-base\index.js:100:9)
11 verbose stack     at callbackError (D:\nodejs\node_modules\npm\node_modules\agent-base\index.js:122:5)
11 verbose stack     at process._tickCallback (internal/process/next_tick.js:68:7)
12 verbose cwd C:\Users\Administrator.L6BFMF7743P5SU1
13 verbose Windows_NT 10.0.17763
14 verbose argv "D:\\nodejs\\node.exe" "D:\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "cnpm" "--registry=https://registry.npm.taobao.org"
15 verbose node v10.15.3
16 verbose npm  v6.4.1
17 error code ETIMEDOUT
18 error errno ETIMEDOUT
19 error network request to https://registry.npm.taobao.org/cnpm failed, reason: connect ETIMEDOUT 93.184.216.34:8080
20 error network This is a problem related to network connectivity.
20 error network In most cases you are behind a proxy or have bad network settings.
20 error network
20 error network If you are behind a proxy, please make sure that the
20 error network 'proxy' config is set properly.  See: 'npm help config'
21 verbose exit [ 1, true ]

Installed many times, are the same error, the installation of online solutions to try a lot of unresolved. Later, according to the log, it was found that it was the agent setting problem.

At first, I thought that the Taobao agent was not effective. Later, when I installed cnpm, I found the same problem, but it was not the problem of Taobao setting.

Note the proxy address printed in the log: 93.184.216.34:8080.

Solution: set the above address and port as proxy

Step one:

npm config set prefix "D:\nodejs\node_global"

Step 2:

npm config set cache "D:\nodejs\node_cache"

Step 3:

npm config set proxy 93.184.216.34:8080

Step 4:

npm config set https-proxy 93.184.216.34:8080

last:

npm install -g cnpm --registry=https://registry.npm.taobao.org

After the above execution, you can enter: cnpm – V to test

 
Refer to node for specific installation process . JS installation and cnpm configuration

Reference article: NPM and cnpm (Windows) installation steps

                   npm ERR ! network connect ETIMEDOUT

NPM and Node.js Version incompatibility

Today, when Xiaobian was installing dependency, he suddenly reported the following error:
. Well, although Xiaobian passed CET-4, he didn’t know which ocean to throw him into, so he went to Baidu to translate.
The result of translation is: the possible node tar or NPM version is the same as node.js This version of is not compatible. Then Xiaobian searches for answers on Baidu, saying that NPM will be downgraded, and the error prompt also says that Xiaobian should mention the version of NPM to be greater than 5.5.1 or less than 5.4.0. However, goose, Xiaobian according to it said downgrade or upgrade operation a wave as fierce as a tiger, the result, ha ha.
So, Xiaobian saw another article on Du Niang. Well, it solved the problem perfectly, so I shared it with you. Xiaobian also took notes.
NPM error

WARNING: You are likely using a version of node-tar or npm that is incompatible with this version of Node.js.
Please use either the version of npm that is bundled with Node.js, or a version of npm (> 5.5.1 or < 5.4.0) or node-tar (> 4.0.1) that is compatible with Node.js 9 and above.
npm[12696]: c:\ws\src\node_zlib.cc:568: Assertion `args.Length() == 7 && "init(windowBits, level, memLevel, strategy, writeResult, writeCallback," " dictionary)"' failed. 
 1: 00007FF7EA10363F napi_wrap+128063
 2: 00007FF7EA0A2836 v8::base::CPU::has_sse+35142
 3: 00007FF7EA0A2B53 v8::base::CPU::has_sse+35939
 4: 00007FF7EA021197 v8::internal::Debug::break_frame_id+84983
 5: 00007FF7EA86DBE0 v8::internal::Builtins::builtin_handle+323456
 6: 00007FF7EA86D127 v8::internal::Builtins::builtin_handle+320711
 7: 00007FF7EA86D468 v8::internal::Builtins::builtin_handle+321544
 8: 00007FF7EA86D26E v8::internal::Builtins::builtin_handle+321038
 9: 00007FF7EAD04EDD v8::internal::SetupIsolateDelegate::SetupHeap+546893
10: 00007FF7EAC89D8C v8::internal::SetupIsolateDelegate::SetupHeap+42748
11: 00007FF7EAC85320 v8::internal::SetupIsolateDelegate::SetupHeap+23696
12: 00007FF7EAD695C0 v8::internal::SetupIsolateDelegate::SetupHeap+958256
15: 00007FF7EAC852F7 v8::internal::SetupIsolateDelegate::SetupHeap+23655
16: 00007FF7EAD695C0 v8::internal::SetupIsolateDelegate::SetupHeap+958256
17: 00007FF7EAC89D8C v8::internal::SetupIsolateDelegate::SetupHeap+42748
18: 00007FF7EAC89D8C v8::internal::SetupIsolateDelegate::SetupHeap+42748
19: 00007FF7EAC89D8C v8::internal::SetupIsolateDelegate::SetupHeap+42748
20: 00007FF7EAC830BC v8::internal::SetupIsolateDelegate::SetupHeap+14892
21: 00007FF7EAC89D8C v8::internal::SetupIsolateDelegate::SetupHeap+42748
22: 00007FF7EAC89D8C v8::internal::SetupIsolateDelegate::SetupHeap+42748

Solution:
1. Uninstall node.js2 Delete the NPM and NPM cache (this step can’t be omitted) under C:: (users/administrator/appdata/roaming)
3. Re install nodejs. Please download the installation files from the official website and click here.
Official website address: https://nodejs.org/zh-cn/download/

4. Open the small blackboard and enter node – V and NPM – V respectively to see the corresponding version number

However, the version of nodejs installed by Xiaobian is 12.16.3, and the corresponding version of NPM is 6.14.4. Ah, in this way, Xiaobian reported another error when running NPMI in other projects: exceeding the maximum stack

Maximum call stack size exceeded

Xiaobian asked Du Niang again that the solution is to go back to a lower version of NMP, that is, to downgrade it. Ah, as a result, only the node corresponding to the lower version of NPM can be installed.

Reprint address: https://blog.csdn.net/qq_ 41241767/article/details/89465508

Crypto JS decrypts malformed UTF-8 data

When using crypto JS to decrypt, an error may be reported:

Malformed UTF-8 data
Error: Malformed UTF-8 data
    at Object.stringify (d:\StudeyCode\myStudy\encryptDemo\routes\encrypt\crypto-js.js:478:27)
    at WordArray.init.toString (d:\StudeyCode\myStudy\encryptDemo\routes\encrypt\crypto-js.js:215:41)
    at decryptByDESModeCBC (d:\StudeyCode\myStudy\encryptDemo\routes\encrypt\crypto.js:90:22)
    at testSign (d:\StudeyCode\myStudy\encryptDemo\routes\test.js:34:18)
    at Layer.handle [as handle_request] (d:\StudeyCode\myStudy\encryptDemo\node_modules\express\lib\router\layer.js:95:5)
    at next (d:\StudeyCode\myStudy\encryptDemo\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (d:\StudeyCode\myStudy\encryptDemo\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (d:\StudeyCode\myStudy\encryptDemo\node_modules\express\lib\router\layer.js:95:5)
    at d:\StudeyCode\myStudy\encryptDemo\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (d:\StudeyCode\myStudy\encryptDemo\node_modules\express\lib\router\index.js:335:12)

The reason for the error is: when des decrypts, if the encrypted data is not an integral multiple of 8, the above error will be reported,
solution: encrypt the data, and then encrypt it with Base64. When decrypting, first decrypt it with Base64, and then decrypt it with DES. The above problems can be solved.

The version number of robot JS running by electron does not match

Solution to the problem of version number mismatch in running electron and robot JS

Running found that the error version number does not match, to reduce the node version number, the result found that it is not the version number problem

<project>/node_modules/robotjs/build/Release/robotjs.node' was compiled against a different Node.js version using 
NODE_MODULE_VERSION 57.
 This version of Node.js requires NODE_MODULE_VERSION 54. 
 Please try re-compiling or re-installing the module (for instance, using npm rebuild or npm install).

After one operation, the node gyp construction error was reported again

node-expat.3.18 install /usr/local/lib/nodejs/node-v14.0.0-linux-x64/lib/node_modules/rnv/node_modules/node-expat node-gyp rebuild

gyp ERR! clean error gyp ERR! stack Error: EACCES: permission denied, rmdir 'build' gyp ERR! System Linux 5.3.0-51-generic gyp ERR! command "/usr/local/lib/nodejs/node-v14.0.0-linux-x64/bin/node" "/usr/local/lib/nodejs/node-v14.0.0-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" gyp ERR! cwd /usr/local/lib/nodejs/node-v14.0.0-linux-x64/lib/node_modules/rnv/node_modules/node-expat gyp ERR! node -v v14.0.0 gyp ERR! node-gyp -v v5.1.0 gyp ERR! not ok npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules/rnv/node_modules/chokidar/node_modules/fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) npm WARN rnv.29.0 requires a peer of now.3.0 but none is installed. You must install peer dependencies yourself.

npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-expat.3.18 install: node-gyp rebuild npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the node-expat.3.18 install 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! /home/abhishek/.npm/_logs/2020-05-10T08_21_14_099Z-debug.log

Solution: to delete the project again and execute the following command again can solve most of the problems
target is the electron version number

By printing console.info ( process.versions );
view the corresponding relationship between
node and ABI: see

cnpm rebuild --runtime=electron --target=8.5.5 --disturl=https://atom.io/download/atom-shell --abi=72

Error: cannot find module HTTP errors

Error description

After creating a new project with express in node, enter

npm start

The system reports an error, as shown in the figure:

Solution

After creating a new project, you should enter the following command:

npm install

Load other dependent modules. And then enter it

npm start

You can start the project normally.

Error reason

When express creates a project, for some libraries, such as HTTP errors , these libraries are not the core modules of node, but they must be used by express framework. So we have to use orders

npm install

Initialize and load these express dependent libraries.