Tag Archives: node

[Solved] node-xlsx Write excel Error: TypeError: n.indexOf is not a function

Use node xlsx to write the assembled data into excel and always report errors. The error information is as follows:

(node:6357) UnhandledPromiseRejectionWarning: TypeError: n.indexOf is not a function
    at /Users/mac/project/reptile/invoice/node_modules/xlsx/xlsx.js:15693:8
    at Array.forEach (<anonymous>)
    at check_ws_name (/Users/mac/project/reptile/invoice/node_modules/xlsx/xlsx.js:15692:11)
    at /Users/mac/project/reptile/invoice/node_modules/xlsx/xlsx.js:15701:3
    at Array.forEach (<anonymous>)
    at check_wb_names (/Users/mac/project/reptile/invoice/node_modules/xlsx/xlsx.js:15700:4)
    at check_wb (/Users/mac/project/reptile/invoice/node_modules/xlsx/xlsx.js:15713:2)
    at Object.writeSync [as write] (/Users/mac/project/reptile/invoice/node_modules/xlsx/xlsx.js:21998:2)
    at Object.build (/Users/mac/project/reptile/invoice/node_modules/node-xlsx/lib/index.js:77:33)
    at writeXlsx (/Users/mac/project/reptile/invoice/index.js:269:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:6357) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:6357) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

There is no useful information in the prompt. You can only use node xlsx to read the normal excel table into JSON, and then compare the normal Josn with the JSON assembled by yourself however, the goose did not find any difference
after careful comparison, the problem is finally found. The reason is that the table name of each table in Excel can only be the string,

let obj = {
    name: more.tatalAmount, // The name obtained here is Number, which must be converted to String with toString()
    data: [
      [
        "111111111"
      ],

[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

nvm npm Error: segmentation fault [How to Solve]

Background

After NVM use switches the node version, NPM reports an error segmentation fault

My solution

sudo apt autoremove npm

Note: it must be autoremove, not remove. Remove is not completely cleared

Cause guess

There is a global NPM. The configuration of the global NPM affects the configuration of the NPM version corresponding to the node installed by the NVM

[Solved] Cnpm installation -g@ view/cli Error: error: eperm: operation not allowed…

After installing node in Windows 10, node – V, NPM – V and cnpm – V are tested to be normal. Cnpm install – G @Vue/cli reports an error
error: eperm: operation not allowed, MKDIR'd:\nodejs\node_global\node_Modules\@Vue'

I found a lot of methods, but I found that the permission was insufficient, so I had a solution
click the attribute in the directory where node is installed to find the security

it’s ok to allow the setting completely

EGG Error: nodejs.Error: Invalid filename [How to Solve]

preface:

This error occurs when using the upload function of egg.

1. Error message:

Error in file name

2. Error reporting reason:

There is no configuration file information in config.default.js, but it is directly obtained in the controller, and an error CTX. Request. Files = = undefined is reported

const file = ctx.request.files[0]; //Get uploaded files

3. Solution:

Add in config.default.js:

//Enable file mode
  config.multipart = {
    mode: 'file'
  }

4. Cause new problems:   Invalid filename: order information.xlsx

5. Solutions to new problems and types have to be set. There is a parameter in the upload that is a white list

Add: whitelist: [‘. Xlsx’] in config.default.js

//Enable file mode
  config.multipart = {
    mode: 'file',
    fileSize: 1048576000,
    whitelist: ['.xlsx']
  }

That’s it!

[Solved] internal/modules/cjs/loader.js:892 ^Error: Cannot find module ‘C:\Users\LX\Desktop\Node_DEMO\a

When I first started learning node.js, I reported an error at the beginning and my mentality collapsed

———————————————————————————–

I create a folder node on my desktop_ Demo, my xx.js file is in node_ demo> demo2> app.js

In vscode, I directly Ctrl + ` (backquote) to open the terminal, but the following error occurs

Look at the path carefully and find that it is wrong. My app.js should be in demo2. Maybe this shortcut does not open the target file….

Therefore, click JS file in the left directory, right-click and select open to open it in the integration terminal~~

Successful problem solving is tiring~~~~

[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

[Solved] Error: read ECONNRESET at TCP.onStreamRead Cannot enqueue Query after fatal error

Error analysis

This error often occurs when I use node to connect to MySQL. I wonder if it is because I do not close the connection every time I query the database after creating a MySQL connection, so the database is always connected and does not respond for a long time, resulting in the following error
error1:

error2:

 

Solution:

error1:

const mysql = require('mysql');
const connInfo = require('./config');

function queryMysql(sql, callback){
    const conn = mysql.createConnection(connInfo)
    conn.query(sql, (err, result)=>{
        if(err){
            console.log(err);
        }else {
            callback(result)
        }
        conn.end(err => {
            if(err){
                console.log(err)
            }
        })
    })
}

module.exports = queryMysql;

Error2:
We only need to configure useConnectionPooling true when instantiating SessionStore for example:

var sessionStore = new SessionStore({
    host: 'localhost' ,
    port: 3306 ,
    user: 'root' ,
    password: 'root' ,
    database: 'session' ,
    useConnectionPooling: true 
});

[Solved] Msbuild: error msb3428: the group cannot use the visual c + + function “vcbuild. Exe”.

After modifying the node version, the project starts to prompt the error message. Nothing has been changed. The error message is as follows:

MSBUILD : error MSB3428: The Visual C++ component "VCBuild.exe" failed to load. To resolve this issue, 1) install the .NET Framework 2.0 SDK; 2) install Microsoft Visual Studio 2005; or 3) if the component is installed in another location, add its location to the system path. [D:\manage\web\node_modules\utf-8-validate\bui
ld\binding.sln]

 

Error reason: missing windows build in

Solution: run as administrator   And open the command-line tool. Run NPM install – global – production windows build tools in the command-line tool.

[Solved] gitbook: node_modules\npm\node_modules\graceful-fs\polyfills.js:287

gitbook:node_modules\npm\node_modules\graceful-fs\polyfills.js:287


1. Exception
Error executing gitbook serve:

C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287
      if (cb) cb.apply(this, arguments)
                 ^

Execute the gitbook serve procedure:

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook
$ gitbook serve
Live reload server started on port: 35729
Press CTRL+C to quit ...

C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287
      if (cb) cb.apply(this, arguments)
                 ^

TypeError: cb.apply is not a function
    at C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287:18
    at FSReqCallback.oncomplete (fs.js:169:5)

2. Environment

node

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook
$ node -v
v12.22.3

npm

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook
$ npm -v
6.14.13

 


3. Solution
My gitbook is installed globally: npm install -g gitbook-cli
According to the error message.
C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287
if (cb) cb.apply(this, arguments)
I switch to the catalog.
C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\
Execute the command:

EB@DESKTOP-K45IA6V MINGW64 ~/AppData/Roaming/npm/node_modules/gitbook-cli/node_modules/npm/node_modules
$ npm install graceful-fs@latest --save
npm notice created a lockfile as package-lock.json. You should commit this file.
+ [email protected]
updated 1 package in 1.308s

Update succeeded (graceful FS).

Try again:

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook
$ gitbook serve
Live reload server started on port: 35729
Press CTRL+C to quit ...

info: 7 plugins are installed
info: loading plugin "livereload"... OK
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 16 pages
info: found 14 asset files
_stream_readable.js:637
  if (state.pipesCount === 1) {
            ^

TypeError: Cannot read property 'pipesCount' of undefined
    at ReadStream.Readable.pipe (_stream_readable.js:637:13)
    at C:\Users\EB\.gitbook\versions\3.2.3\node_modules\cpr\lib\index.js:163:22
    at callback (C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:299:20)
    at FSReqCallback.oncomplete (fs.js:168:21)

Still report an error!

Final solution:

reference resources: https://blog.csdn.net/test1280/article/details/118961808

Downgrade nodejs version to: node-v9.11.2-x64.msi

Try again:

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook
$ gitbook init
info: create SUMMARY.md
info: initialization is finished

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook
$ gitbook serve
Live reload server started on port: 35729
Press CTRL+C to quit ...

info: 7 plugins are installed
info: loading plugin "livereload"... OK
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 16 pages
info: found 14 asset files
info: >> generation finished with success in 1.2s !

Starting server ...
Serving book on http://localhost:4000

Successfully started:


5. Postscript

5.1.case1

node-v14.17.3-x64.msi

Gitbook init error:

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook
$ gitbook init
Installing GitBook 3.2.3
C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287
      if (cb) cb.apply(this, arguments)
                 ^

TypeError: cb.apply is not a function
    at C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287:18
    at FSReqCallback.oncomplete (fs.js:193:5)

Gitbook init error (or):

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook
$ gitbook init
warn: no summary file in this book
info: create README.md
info: create SUMMARY.md

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Promise

5.2.case2

node-v12.22.3-x64.msi

gitbook server error:

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook
$ gitbook serve
Live reload server started on port: 35729
Press CTRL+C to quit ...

C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287
      if (cb) cb.apply(this, arguments)
                 ^

TypeError: cb.apply is not a function
    at C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:287:18
    at FSReqCallback.oncomplete (fs.js:169:5)

Update graceful FS and still report an error:

EB@DESKTOP-K45IA6V MINGW64 ~/Desktop/test1280-gitbook
$ gitbook serve
Live reload server started on port: 35729
Press CTRL+C to quit ...

info: 7 plugins are installed
info: loading plugin "livereload"... OK
info: loading plugin "highlight"... OK
info: loading plugin "search"... OK
info: loading plugin "lunr"... OK
info: loading plugin "sharing"... OK
info: loading plugin "fontsettings"... OK
info: loading plugin "theme-default"... OK
info: found 16 pages
info: found 14 asset files
_stream_readable.js:637
  if (state.pipesCount === 1) {
            ^

TypeError: Cannot read property 'pipesCount' of undefined
    at ReadStream.Readable.pipe (_stream_readable.js:637:13)
    at C:\Users\EB\.gitbook\versions\3.2.3\node_modules\cpr\lib\index.js:163:22
    at callback (C:\Users\EB\AppData\Roaming\npm\node_modules\gitbook-cli\node_modules\npm\node_modules\graceful-fs\polyfills.js:299:20)
    at FSReqCallback.oncomplete (fs.js:168:21)

5.3. Case 3

Node-v9.11.2-x64.msi

Russian.

Cannot find module ‘.. / lib / utils / unsupported. JS’ problem in installing node in centos7

When installing node in centos7 virtual machine, an error is reported: cannot find module ‘…/lib/utils/unsupported. JS’. The complete error is as follows:

the prompt is that an unsupported.js file cannot be found. Finally, it is found that the soft connection is wrong when installing this version of node in centos7, This problem may not be solved by re installation (at present, I only encounter this problem in the virtual machine of centos7). Delete the original NPM connection and re create one.

1. First, download the CD to the bin folder of the node version, where version 12.16.2 is installed

cd /opt/node-v12.16.2-linux-x64/bin

2. Delete the NPM file in the path, and enter yes when prompted

rm npm

3. Reestablish file connection

ln -s ../lib/node_modules/npm/bin/npm-cli.js ./npm

Using NPM – V command again, it is found that it is almost OK.
the whole operation is shown as follows:

error Unable to authenticate, need: BASIC realm=“Sonatype Nexus Repository Manager“

Today, when I was working on the Vue project to switch private service nexus and NPM login, I encountered the following problem: error unable to authenticate, need: basic realm = “sonatype nexus repository manager”
I searched the Internet, it seems that I may encounter this problem when I log in, register and publish. The reason for the problem is also very clear, Is the authority verification failed. The following is my online solution integration

First, the information input is incorrect. Carefully compare whether the user, password and email you input are correct (do not use the password remembered on the webpage to log in, because it may have been changed.)
the second method: if it’s registration, the user name may have been used
the third method: clear cache: NPM cache clear — force
I’ve tried all the above methods, but it doesn’t solve my problem, The following is my way to solve the problem
the fourth method: add permissions to the private service
(1) the browser logs in to the private service
(2) settings – security – realms – add NPM bearer token realm to the active
the fifth method: the Limited Download address in. Package-lock.json conflicts with the address you use

Check the address used: NRM is to see if it is consistent with the address in package-lock.json. This is my latest problem. When I visit Taobao image and https://registry.npmjs.org/
solution: delete package-lock.json