background
Running environment : CentOS Linux release 7.5.1804
node version : v16.19.0
Runtime execution : npm install
error is as follows :
vue-demi@0.13.11 postinstall /root/h-management-prototype/node_modules/@nuxtjs/i18n/node_modules/vue-demi
node ./scripts/postinstall.js
node:internal/fs/utils:347
throw err;
^
Error: EACCES: permission denied, open '/root/h-management-prototype/node_modules/@nuxtjs/i18n/node_modules/vue-demi/lib/index.cjs'
at Object.openSync (node:fs:590:3)
at Object.writeFileSync (node:fs:2202:35)
at copy (/root/h-management-prototype/node_modules/@nuxtjs/i18n/node_modules/vue-demi/scripts/utils.js:24:6)
at switchVersion (/root/h-management-prototype/node_modules/@nuxtjs/i18n/node_modules/vue-demi/scripts/utils.js:52:3)
at Object.<anonymous> (/root/h-management-prototype/node_modules/@nuxtjs/i18n/node_modules/vue-demi/scripts/postinstall.js:15:3)
at Module._compile (node:internal/modules/cjs/loader:1165:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1219:10)
at Module.load (node:internal/modules/cjs/loader:1043:32)
at Function.Module._load (node:internal/modules/cjs/loader:878:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
errno: -13,
syscall: 'open',
code: 'EACCES',
path: '/root/h-management-prototype/node_modules/@nuxtjs/i18n/node_modules/vue-demi/lib/index.cjs'
}
Reason for error
In Linux systems, the root user does not automatically obtain the installation permission for npm packages and needs to manually set permissions.
Solution
--unsafe-perm=true
This problem can be solved by adding the parameter when executing the npm command . This parameter will tell npm not to check permissions during the installation of the package, and execute it directly as the root user.
npm i --unsafe-perm=true
Notice
Using --unsafe-perm=true
the parameter will cause npm to execute as the root user, which may cause potential security risks to the system. Therefore, it is recommended to use this parameter only when necessary.