Tag Archives: node.js

Error: Cannot find module ‘./application‘ [How to Solve]

1. Background:

Run in PowerShell: PS e: \ vscode \ Vue \ day4 \ code \ myapi & gt; nodemon . \index. JS
error reporting

2. Error reporting content:

PS E:\vscode\vue\day4\code\myapi> node .\index.js
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module './application'
Require stack:
- E:\vscode\vue\day4\code\myapi\node_modules\express\lib\express.js
- E:\vscode\vue\day4\code\myapi\node_modules\express\index.js
- E:\vscode\vue\day4\code\myapi\index.js
[90m    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)[39m
[90m    at Function.Module._load (node:internal/modules/cjs/loader:778:27)[39m
[90m    at Module.require (node:internal/modules/cjs/loader:1005:19)[39m
[90m    at require (node:internal/modules/cjs/helpers:102:18)[39m
    at Object.<anonymous> (E:\vscode\vue\day4\code\myapi\node_modules\[4mexpress[24m\lib\express.js:18:13)
[90m    at Module._compile (node:internal/modules/cjs/loader:1101:14)[39m
[90m    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)[39m
[90m    at Module.load (node:internal/modules/cjs/loader:981:32)[39m
[90m    at Function.Module._load (node:internal/modules/cjs/loader:822:12)[39m
[90m    at Module.require (node:internal/modules/cjs/loader:1005:19)[39m {
  code: [32m'MODULE_NOT_FOUND'[39m,
  requireStack: [
    [32m'E:\\vscode\\vue\\day4\\code\\myapi\\node_modules\\express\\lib\\express.js'[39m,
    [32m'E:\\vscode\\vue\\day4\\code\\myapi\\node_modules\\express\\index.js'[39m,
    [32m'E:\\vscode\\vue\\day4\\code\\myapi\\index.js'[39m
  ]
}

3. Solution:

1. Prompt for finding the error point: error: cannot find module ‘/ application’
2. According to the error prompt, baidu solved the first blog

4. Causes:

Execute node \index. JS, PowerShell did not find ‘/ Application ‘this module should be index JS file runtime calls
node_ The dependent module in the modules folder is not found, so an error is reported

5. Solution:

1. Delete node_Modules folder (because dependencies are placed here)
2 There is a package Run in the folder of JSON file: PS e:\vscode\Vue\day4\code\myapi > npm install
3. The previous step is based on package JSON file re download dependency

[Solved] NRM Error: error code: ‘err’_INVALID_ARG_Type ‘

Commandnpm install nrm -g to install nrm 1.2.1 error:

[TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
  at validateString (internal/validators.js:122:11)
  at Object.join (path.js:375:7)
  at Object.<anonymous> (C:\Users\liyin\AppData\Roaming\npm\node_modules\nrm\cli.js:17:20)
  at Module._compile (internal/modules/cjs/loader.js:1076:30)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
  at Module.load (internal/modules/cjs/loader.js:941:32)
  at Function.Module._load (internal/modules/cjs/loader.js:782:14)
  at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
  at internal/main/run_main_module.js:17:47

] {
  code: 'ERR_INVALID_ARG_TYPE'
}

Locate the NRM directory (error line 4)

Open cli.js line 17 is modified to

//const NRMRC = path.join(process.env.HOME, '.nrmrc'); (DELETE)
const NRMRC = path.join(process.env[(process.platform == 'win32') ?'USERPROFILE' : 'HOME'], '.nrmrc');

After saving, reopen the command line to run the NRM LS command normally

C:\Windows\system32>nrm ls
  npm -------- [https://registry.npmjs.org/](https://registry.npmjs.org/)
  yarn ------- [https://registry.yarnpkg.com/](https://registry.yarnpkg.com/)
  cnpm ------- [http://r.cnpmjs.org/](http://r.cnpmjs.org/)
- taobao ----- [https://registry.npm.taobao.org/](https://registry.npm.taobao.org/)
  nj --------- [https://registry.nodejitsu.com/](https://registry.nodejitsu.com/)
  npmMirror -- [https://skimdb.npmjs.com/registry/](https://skimdb.npmjs.com/registry/)
  edunpm ----- [http://registry.enpmjs.org/](http://registry.enpmjs.org/)
  [TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:122:11)
    at Object.join (path.js:375:7)
    at Object.<anonymous> (C:\Users\liyin\AppData\Roaming\npm\node_modules\nrm\cli.js:17:20)
    at Module._compile (internal/modules/cjs/loader.js:1076:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
    at Module.load (internal/modules/cjs/loader.js:941:32)
    at Function.Module._load (internal/modules/cjs/loader.js:782:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47
  ] {
    code: 'ERR_INVALID_ARG_TYPE'
  }

[Solved] npm link Error: error Error: EPERM: operation not permitted;The operation was rejected by your operating

Error message:

Solution:

From the error message, the prompt is that the permission is insufficient to operate. All the files found on the Internet are to delete npmrc files, but there is no effect. Through exploration, we can solve it in two ways:
1. Run vscode as an administrator, and then run NPM link on the vscode terminal
2. Run CMD (command prompt) as an administrator, Go into your own module and run NPM link

it’s done

[Solved] NPM install error: Maximum call stack size exceeded

1. Scene reproduction

Today, I wanted to pull someone else’s code to have a look, and then NPM install reported this error: “maximum call stack size exceeded”. I haven’t seen this error before, and finally found a solution.

2. Solution

1. Upgrade NPM, NPM install – G NPM
2 Re execute, NPM/cnpm install
3 If not, try clearing the NPM cache. NPM cache clean — force
4 Re execute, NPM/cnpm install

Cocos creator custom engine NPM Error [How to Fix]

Background

Cocos creator compilation engine NPM install reports errors
error contents:

fetchMetadata: sill pacote range manifest for [email protected]^0.1.1 fetched in 194ms

Solution:

The effective scheme is as follows:

npm config set registry http://registry.npmjs.org/ --global
npm cache clear --force
npm install --verbose

Type

[Solved] node.js Upload Files Error: Multipart: boundary not found multer

Today, when the front-end uses Vue to transfer files with formdata, the background node reports an error

Multipart: Boundary not found multer

It is found in the front console that the file file transmitted by the interface is null {}, because it is set when Axios requests

the Header of Content-Type is multipart/form-data

It is found that there is no boundary parameter later, except multipart/form data

multipart/form-data;boundary :****************

There should also be a series of boundary parameters. First of all, do not splice the contents behind the boundary, otherwise you need to reconfigure all the content parameters yourself.
later, it is found that it is the reason for the request method, and you need to use ajax to make the request.
the solution is as follows

// upload the files
export function reqUploadImg(file, user_id) {
  return axios({
    url: '/uploadImg',
    method: 'POST',
    Headers: {
      "content-type": "multipart/form-data",
    },
    data: file,
    params: { user_id }
  })
}

This problem can be solved. It will automatically splice a string later, or “content type”: “multipart/form-data” in “multipart/form-data” will also be spliced automatically if it is set to fasle, but after personal experiments, it is found that the types have changed into JSON format, which is automatically generated by Axios source code

[Solved] error: mongoosserverselectionerror: connect econnreused 127.0 0.1:27017

Mongodb suddenly reported an error, the foreground could not get the data, and the mongodb software could not be opened

node:22368) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at NativeConnection.Connection.openUri (D:\HBuilder work place\huaRui\2.0\serve\node_modules\mongoose\lib\connection.js:797:32)

Solution: Task Manager — Service — mongodb — Open

[Solved] NPM run build package error: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory

1. Phenomenon

It has always been normal. Suddenly one day, an error is reported when packing. The key information is as follows:
ineffective mark compacts near heap limit allocation failed - Javascript heap out of memory
the details are as follows:

2. Solution

All kinds of data say that node memory overflow , and solutions are also given,
for example: – max_old_space_Size = 4096 and so on, but it doesn’t work for me. (if you refer to mine, it doesn’t work, you can look at the other methods mentioned above)
later, I saw a solution, which worked
1, CMD Global install increase memory limit
NPM install -g increase memory limit

2, CD enter the project directory and execute:
increase memory limit

3. Repack
NPM run build

(node:268660) UnhandledPromiseRejectionWarning: Error: Cannot find module ‘yallist‘

NPM command error in vscode

In Vue (node: 268660) unhandledpromiserejectionwarning: error: cannot find module ‘yallist’ problem solving delete the under C: \ users \ [current user name] Npmrc file Npmrc file content:

In Vue (node: 268660), unhandledpromiserejectionwarning: error: cannot find module ‘yallist’ problem solving

Delete the under C: \ users [current user name] Npmrc file

. Npmrc file content:

cache=C:\Software\Tool\nodejs\node_cache
prefix=C:\Software\Tool\nodejs\node_global
registry=https://registry.npm.taobao.org

Using ts-node to Execute .ts files Error [Solved]

When learning typescript, you want to execute the TS file. First install the TS package, then use the TSC command to execute it, compile it into a JS file, and use node xxx.js to execute it. However, this is troublesome. Later, you want to use TS node to directly execute it and simplify the steps. An error is reported:

It is found that the corresponding package needs to be installed to compile:

Solution:
 
npm install -D tslib @types/node

Node.js Error: throw er; // Unhandled ‘error‘ event [How to Solve]

Original console output:

node:events:368
      throw er; // Unhandled 'error' event
      ^

Error [ERR_STREAM_WRITE_AFTER_END]: write after end
    at new NodeError (node:internal/errors:371:5)
    at ServerResponse.end (node:_http_outgoing:846:15)
    at Server.<anonymous> (D:\files\Web_videos\Node\server\app.js:30:13)
    at Server.emit (node:events:390:28)
    at parserOnIncoming (node:_http_server:951:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
Emitted 'error' event on ServerResponse instance at:
    at emitErrorNt (node:_http_outgoing:726:9)
    at processTicksAndRejections (node:internal/process/task_queues:84:21) {
  code: 'ERR_STREAM_WRITE_AFTER_END'
}

Error reason:

The port number is occupied.

Solution:  

Modify the port number, or kill the port number and restart the project

How to kill the port number:

1. Enter the CMD command window and write netstat – ano|findstr “8080”

2.taskkill -PID 13512 -F