Tag Archives: node.js

node.js yarn Error: SyntaxError: Unexpected string [How to Solve]

Error log:

exec "/home/latte-with-ice/.nvm/versions/node/v16.17.0/bin/node" "/home/latte-with-ice/.nvm/versions/node/v16.17.0/bin/yarn" "$@"
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected string
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1055:15)
    at Module._compile (node:internal/modules/cjs/loader:1090:27)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)

Error Cause.
There are two types of yarn installed by system apt install yarn and npm install yarn

Solution:

  1. Uninstall system yarn first: sudo apt-get remove yarn && sudo apt-get
  2. [can not do] uninstall yarn from node: npm uninstall -g yarn
  3. Reinstall yarn: npm install -g yarn
  4. Re-execute the program and it will work again

[Solved] Mac Notebook M1 Chip Install Hashlips library npm error

Mac notebook M1 chip installs Hashlips library npm error problem

Foreword

When generating NFT, we often prepare all the materials needed for NFT, and then stack each material on the same canvas to generate an NFT, but if we manually It’s too troublesome to stack one by one, because NFTs are often issued in thousands of ten thousand, so manual generation is unrealistic, So what can we do to generate It, Is to use the computer, There are many similar tools on the Internet, There are graphical and pure code, And many use Paython to generate NFT, But there is a node abroad The script tool Hashlips can directly use node to generate, and it is very convenient and powerful to use, There was no problem when using the windows system before, After changing the MBP later, I found that Hashlips reported an error when executing npm install

image-20220913144839078

Cause Analysis

After various searches and research, I found that Hashlip is implemented with canvas canvas, Then I touched the node-canvas library, There is a very similar problem in the issue of this library, which probably means that the Mac with m1 chip cannot directly use npm to install the library to node-canvas, You need to use Homebrewto install what you need.

image-20220913145139869

Solution

Official solution

In fact, both node-canvas and hasllips have released solutions one after another,The solution is actually the same,The following is hasllips The method approved in the official issue

The correct method is as follows:

1. Download and install Node.js "Current" version, as opposed to the "LTS" (Long Term Support) version. This is now v18.0.0 as of the time of this post , but 17.x will work as well:
2. Ensure you have homebrew installed. You can go to or just use this command: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install .sh)" to install Homebrew.
3. Install the dependencies via Homebrew using this command: arch -arm64 brew install pkg-config cairo pango jpeg giflib librsvg
4. In your root folder for the art engine project, install the project: npm install

The correct way is as follows:

1. Download and install the latest version of Node.js , instead of the "LTS" (Long Term Support) version.
2. Install Homebrew.
3. Install dependencies via Homebrew using the following command :arch -arm64 brew install pkg-config cairo pango jpeg giflib librsvg
4. In the root folder of your art engine project ,install the project:npm install

My solution

Combined with the above solution, The landlord did not upgrade the node version to the latest version, but used the LTS long-term support version of Node16.6, then Directly use Homebrew to execute the command brew install pkg-config cairo pango libpng jpeg giflib librsvg pixmaninstall

Wait for the above installation to complete,npm install or yarn install directly in the project

[Solved] Internal Error: EPERM: operation not permitted, open

When installing yarn on nodejs (my version: 16.17), after executing the command: corepack enable, I got an error: Internal Error: EPERM: operation not permitted, open 'Y:\nodejs-v16.17.0-x64\pnpm, The operation is not allowed, I thought of the previous execution of rm -rf /* with linux normal user will also prompt not allowed to execute the operation, and change to root (administrator) account to have higher privileges to execute the command, so I guess it should be the same problem, so I tried to run the cmd command window as administrator, and execute the command: corepack enable again, it succeeded It worked:

Error: error:0308010C:digital envelope routines::unsupported [How to Solve]

Error message:

When the front-end project is started (npm run dev) and packaged (npm run build:prod), the following error is reported:

Error: error:0308010C:digital envelope routines::unsupported
    at new Hash (node:internal/crypto/hash:71:19)
    at Object.createHash (node:crypto:133:10)
    at module.exports 
....
 
at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3) {
  opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
  library: 'digital envelope routines',
  reason: 'unsupported',
  code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

Cause of problem:

The reason for this is that nodeJs V17 released OpenSSL3.0 with stricter restrictions on the algorithm and secret key size, which did not affect versions before nodeJs v17, but this error will occur in V17 and later versions.

Solution (windows only):

Add SET NODE_OPTIONS=--openssl-legacy-provider in the scripts of the package.json 
Before:
"scripts": {
    "dev": "vue-cli-service serve",
    "build:prod": "vue-cli-service build"
  },
  
Added:
"scripts": {
    "dev": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve",
    "build:prod": "SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service build"
  },


Note: If the node version in the team is not the same, do not submit the package.json.
My v18.8.0 does not add this directive, my colleague is v14.17.3, adding this directive will report an error

[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

How to Solve npm-install Command -4048 Error

When I reinstall the computer system, I download the front-end environment configuration again. An error occurs when configuring NPM. The main error messages are as follows:

npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'E:\work\node\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'E:\work\node\node_cache\_logs\2022-08-24T09_17_13_819Z-debug-0.log'
npm WARN logfile could not create logs-dir: Error: EPERM: operation not permitted, mkdir 'E:\work\node\node_cache\_logs'
npm WARN logfile could not be created: Error: ENOENT: no such file or directory, open 'E:\work\node\node_cache\_logs\2022-08-24T09_17_14_514Z-debug-0.log'
npm ERR! code EPERM
npm ERR! syscall mkdir
npm ERR! path E:\work\node\node_cache\_cacache
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, mkdir 'E:\work\node\node_cache\_cacache'
npm ERR!  [Error: EPERM: operation not permitted, mkdir 'E:\work\node\node_cache\_cacache'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: 'E:\\work\\node\\node_cache\\_cacache'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! Log files were not written due to an error writing to the directory: E:\work\node\node_cache\_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

First, check whether the parameters of system environment configuration and user environment configuration are consistent

Click the path in the system environment configuration to observe whether the path is consistent. This may be my personal reason. After reinstalling node several times, the path here is inconsistent. After the change, it is still not possible.

I thought it was caused by the command line permission problem, and found that using the administrator still does not work, and then I searched the Internet for the reason and finally found it;

  1. Find the .npmrc file under C:\Users\{account}\ and delete it
  2. After clearing npm cache:npm cache clean –force
  3. Then run the npm install command.

[Solved] npm install Error: error code ERR_SOCKET_TIMEOUT

1. Error information

New project, Vue + element, NPM install, The error information reported at that time is as follows.

error code ERR_SOCKET_TIMEOUT
9673 error network Socket timeout
9674 error network This is a problem related to network connectivity.
9674 error network In most cases you are behind a proxy or have bad network settings.
9674 error network
9674 error network If you are behind a proxy, please make sure that the
9674 error network 'proxy' config is set properly.  See: 'npm help config'
9675 verbose exit 1
9676 timing npm Completed in 545124ms
9677 verbose unfinished npm timer reify 1661242562981
9678 verbose unfinished npm timer reify:unpack 1661242811008
9679 verbose unfinished npm timer reifyNode:node_modules/svgo 1661242811170
9680 verbose code 1

2. Solutions

//Step 1


npm install webpack webpack-cli --global



//Step 2
npm install rxjs



//Step 3
npm install webpack webpack-cli --global



//Finally, direct boot success
npm run dev 

 

[Solved] VSCode package Error: Command failed: npm list –production –parseable –depth=99999 –loglevel=error

After VSCode package, there is an error report: command failed: NPM list –production –parseable –depth=99999 –loglevel=error appears. missing: vsce@^2.10.0, required by [email protected]

Note: this error pops up when I try to package the vscode plug-in

I found that many situations may lead to this error Command failed: npm list --production --parseable --depth=99999 --loglevel=error. Please pay attention.

reason

After some troubleshooting, I found that the reason I got this error was because I started installing the vsce package in the current location, and then I decided that it was wrong and changed it to a global installation. Then, instead of uninstalling vsce from the current location, I just deleted the node_modules folder. The error occurred because the vsce package command was not executed correctly because it was not uninstalled and then deleted.

 

Solution:

Reinstall the vsce package at the current location, npm install vsce,

Use npm uninstall vsce to uninstall.

Finally, you can choose to delete node_modules folder.

 

[Solved] gyp ERR! stack Error: Could not find any Python installation to use

Header error prompt

gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | win32 | x64
gyp ERR! find Python
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON

Tail error prompt

gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python="C:\Path\To\python.exe"
gyp ERR! find Python   (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python   npm config set python "C:\Path\To\python.exe"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack     at PythonFinder.fail (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:330:47)
gyp ERR! stack     at PythonFinder.runChecks (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:159:21)
gyp ERR! stack     at PythonFinder.<anonymous> (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:248:16)
gyp ERR! stack     at PythonFinder.execFileCallback (D:\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.js:294:16)
gyp ERR! stack     at exithandler (node:child_process:406:5)
gyp ERR! stack     at ChildProcess.errorhandler (node:child_process:418:5)
gyp ERR! stack     at ChildProcess.emit (node:events:527:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:289:12)
gyp ERR! stack     at onErrorNT (node:internal/child_process:478:16)
gyp ERR! stack     at processTicksAndRejections (node:internal/process/task_queues:83:21)
gyp ERR! System Windows_NT 10.0.22000
gyp ERR! command "D:\\nodejs\\node.exe" "D:\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd G:\aidex\font-end\aidex-ui\node_modules\deasync
gyp ERR! node -v v16.15.1
gyp ERR! node-gyp -v v9.0.0
gyp ERR! not ok

Solution:

NPM installation

npm i -g node-gyp

Yarn installation

yarn global add  node-gyp