Laravel mix npm run dev on linux produce SyntaxError: missing ) after argument list - node.js

I can't use npm run dev|prod|watch on my staging linux server. It produces this :
npm run production
glob error [Error: EACCES: permission denied, scandir '/root/.npm/_logs'] {
errno: -13,
code: 'EACCES',
syscall: 'scandir',
path: '/root/.npm/_logs'
}
> production
> mix --production
/var/www/html/preprodCerf2021/node_modules/laravel-mix/bin/cli.js:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at Object.compileFunction (node:vm:352:18)
at wrapSafe (node:internal/modules/cjs/loader:1031:15)
at Module._compile (node:internal/modules/cjs/loader:1065:27)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
at node:internal/main/run_main_module:17:47
nodeJs is up to date v 16.8.0 and npm v 7.21.0 my the compilation works perfectly on my windows dev machine.
This is the files ownership :
-rwxr-xr-x 1 www-data www-data 817 sept. 30 10:06 package.json
-rw-r--r-- 1 www-data www-data 820729 sept. 30 10:32 package-lock.json
-rwxr-xr-x 1 www-data www-data 1202 janv. 22 2021 phpunit.xml
drwxr-xr-x 8 www-data www-data 4096 sept. 8 16:02 public
-rwxr-xr-x 1 www-data www-data 3780 janv. 22 2021 README.md
drwxr-xr-x 8 www-data www-data 4096 août 31 12:55 resources
drwxr-xr-x 2 www-data www-data 4096 janv. 28 2021 routes
-rwxr-xr-x 1 www-data www-data 563 janv. 22 2021 server.php
drwxrwxr-x 6 www-data www-data 4096 mars 5 2021 storage
-rwxr-xr-x 1 www-data www-data 181 janv. 22 2021 .styleci.yml
-rwxr-xr-x 1 www-data www-data 548 sept. 9 15:36 tailwind.config.js
drwxr-xr-x 4 www-data www-data 4096 janv. 28 2021 tests
drwxr-xr-x 61 www-data www-data 4096 août 31 12:56 vendor
-rwxr-xr-x 1 www-data www-data 669 sept. 30 11:58 webpack.mix.js

I've faced similar issues where I was trying to run npm as root user but the file ownership was with different users. You can try one of the following ways:
Try running npm with the www-data user
Change ownership of the files to a sudoable user
# login as a user that has sudo access and change file ownership
sudo chown -R myuser:myuser /path/to/project/
# run npm commands as myuser
npm install && npm run production
# change the permissions to previous state
sudo chown -R www-data:www-data /path/to/project/
Change ownership of the files to the root user (this hasn't worked for me so far but may work for you)
# enter sudo mode and change ownership to root
sudo su
chown -R root:root /path/to/project/
# run npm commands as root user
npm install && npm run production
# change the permissions to previous state
chown -R www-data:www-data /path/to/project/
# exit sudo mode
exit

In the end I tried this succesfully, npm is very mysterious
rm node_modules -rf && npm install

Related

suid is not honoured inside docker container

I downloaded sudo in my DockerFile
RUN yum -y update &&
yum -y install which sudo
I have set suid bit on it
RUN chown root:root /usr/bin/sudo
RUN chmod 4755 /usr/bin/sudo
In container I see lot of binaries with suid bit set
root#89f28b09dee0 go]# ls -la /usr/bin/* | grep rwsr
-rwsr-xr-x 1 root root 73888 Aug 9 2019 /usr/bin/chage
-rwsr-xr-x 1 root root 78408 Aug 9 2019 /usr/bin/gpasswd
-rwsr-xr-x 1 root root 44264 Aug 9 2019 /usr/bin/mount
-rwsr-xr-x 1 root root 41936 Aug 9 2019 /usr/bin/newgrp
-rwsr-xr-x 1 root root 27856 Aug 9 2019 /usr/bin/passwd
-rwsr-xr-x 1 root root 32128 Aug 9 2019 /usr/bin/su
-rwsr-xr-x 1 root root 147320 Aug 9 2019 /usr/bin/sudo
-rwsr-xr-x 1 root root 31984 Aug 9 2019 /usr/bin/umount
Other binaries which are part of base image works seelessly
[test#89f28b09dee0 go]$ passwd
Changing password for user test.
Changing password for test.
(current) UNIX password:
But sudo fails
sudo
sudo: effective uid is not 0, is /usr/bin/sudo on a file system with the 'nosuid' option set or an NFS file system without root privileges?
[test#89f28b09dee0 go]$
Most of search on internet says it may be because of filesystem permission but other binaries are working fine from same location with suid bit set.

add write access to user ubuntu - shared folder cifs-utils

I have folder in /media on ubuntu - shared from windows via fstab and cifs-utils. Can I share this folder to other user: "miki" (not root)
root#localhost:/media#
drwxr-xrwx 4 root root 4096 Nov 15 12:21 .
drwxr-xr-x 23 root root 4096 Nov 14 06:34 ..
drwxr-xr-x 2 padm root 0 Nov 15 09:34 Archive
drwxr-xrwx 2 root root 4096 Feb 25 2019 kekik
I have try with:
root#localhost:~# sudo chmod -R 757 /media/Archive/
but get:
chmod: changing permissions of '/media/Archive/': Permission denied
Find a solution:
need to modify /etc/fstab by changing:
//windowsServer/Archive /media/Archive cifs username=wundowsuser,password=somepass,uid=1000,iocharset=iso8859-1,rw,file_mode=0777,dir_mode=0777,vers=1.0 0 0
and change group of folder (must umont it first!)
sudo umount -l /media/Archive
sudo chown miki:miki /media/Archive/

Tomcat installed folder access is denied on linux

Please find below set of cmds & outputs
[ec2-user#ip-172-31-38-218 opt]$ ls -al
total 9416
drwxr-xr-x 3 root root 4096 Nov 7 13:52 .
dr-xr-xr-x 25 root root 4096 Nov 7 13:16 ..
-rw-r--r-- 1 root root 9625824 Sep 4 22:52 apache-tomcat-8.5.34.tar.gz
drwxr-xr-x 5 root root 4096 Aug 11 01:26 aws
[ec2-user#ip-172-31-38-218 opt]$ sudo groupadd tomcatgrp
[ec2-user#ip-172-31-38-218 opt]$ sudo useradd -s /bin/false -g tomcatgrp -d /opt/tomcatfolder tomcatuser
[ec2-user#ip-172-31-38-218 opt]$ ls -al
total 9420
drwxr-xr-x 4 root root 4096 Nov 7 13:53 .
dr-xr-xr-x 25 root root 4096 Nov 7 13:16 ..
-rw-r--r-- 1 root root 9625824 Sep 4 22:52 apache-tomcat-8.5.34.tar.gz
drwxr-xr-x 5 root root 4096 Aug 11 01:26 aws
drwx------ 2 tomcatuser tomcatgrp 4096 Nov 7 13:53 tomcatfolder
Now, when I run the cmd I am getting Permission denied as follows
[ec2-user#ip-172-31-38-218 opt]$ cd /opt/tomcatfolder/
-bash: cd: /opt/tomcatfolder/: Permission denied
Can you please help in resolving this above issue..?
I followed instructions of installing Tomcat from this link how-to-install-apache-tomcat-8-on-centos-7
It seems you are the ec2-user, but the directory is owned by tomcatuser and the permissions on the directory do now allow other users or groups to read it.
Try sudo chmod 755 /opt/tomcatfolder/ and then cd into it.
That will add read and execute permissions to the directory.

Executing Karma giving permission denied error

I installed karma locally using
npm install karma --save-dev
and then i tried
$ ./node_modules/karma/bin/karma start
Then i get this error
vagrant#development:$ ./node_modules/karma/bin/karma start
-bash: ./node_modules/karma/bin/karma: Permission denied
vagrant#development:$ ls -liah ./node_modules/karma/bin/
total 4.0K
54696 drwxrwxr-x 1 vagrant www-data 102 Nov 17 19:24 .
54688 drwxrwxr-x 1 vagrant www-data 544 Nov 17 15:57 ..
54697 -rw-rw-r-- 1 vagrant www-data 50 Nov 15 02:43 karma
What can be the reason
http://karma-runner.github.io/0.12/intro/installation.html
vagrant#development:$ sudo chmod +x ./node_modules/karma/bin/karma
vagrant#development:$ ls -liah ./node_modules/karma/bin/
total 4.0K
54696 drwxrwxr-x 1 vagrant www-data 102 Nov 17 19:24 .
54688 drwxrwxr-x 1 vagrant www-data 544 Nov 17 15:57 ..
54697 -rw-rw-r-- 1 vagrant www-data 50 Nov 15 02:43 karma
Your ./node_modules/karma/bin/karma executable does not have execution privileges for your user. You can chmod it to give you the right privileges with:
$ chmod +x ./node_modules/karma/bin/karma
To avoid this in the future, simply install it with npm install -g karma-cli (globally).

Can't run npm-installed packages as user

Earlier this afternoon I installed Node.js on Fedora 16.
user#$ sudo yum localinstall --nogpgcheck http://nodejs.tchol.org/repocfg/fedora/nodejs-stable-release.noarch.rpm
user#$ sudo yum install nodejs-compat-symlinks npm
Then I installed a package with npm. Every package I've installed with npm on Fedora (this isn't my first time) has involved something like the following process. Read it and weep. Clearly, this is hackish and wrong, but when I decide to install less or any other npm package, I have to go through the same procedure. Why? What is broken about my environment or approach?
user#$ sudo npm install -g jslint
[... this works ... kind of]
user#$ jslint
bash: jslint: command not found
user#$ sudo su
root#$ jslint
No files specified.
Usage: /bin/jslint ... [works]
root#$ which jslint
/bin/jslint
root#$ ls -l jslint
lrwxrwxrwx. 1 root root 38 Jul 15 14:58 /bin/jslint -> /lib/node_modules/jslint/bin/jslint.js
root#$ cd /lib/node_modules; ls -l
...
drwxr-xr-x. 2 root root 4096 Jul 15 14:22 inherits
drwxr-xr-x. 2 root root 4096 Jul 15 14:22 ini
drwx------. 6 nobody usergroup 4096 Jul 15 14:58 jshint
drwxr-xr-x. 3 root root 4096 Jul 15 14:22 lru-cache
...
root#$ find . -type d -print0 | xargs -0 chmod 755
root#$ ls -l
...
drwxr-xr-x. 2 root root 4096 Jul 15 14:22 inherits
drwxr-xr-x. 2 root root 4096 Jul 15 14:22 ini
drwxr-xr-x. 5 nobody usergroup 4096 Jul 15 15:32 jslint
drwxr-xr-x. 3 root root 4096 Jul 15 14:22 lru-cache
...
root#$ su user
user#$ jslint
o files specified.
Usage: /bin/jslint [now it finally works]
Recent versions of npm switch to user "nobody" as a security measure if it's being run with sudo privileges. Try doing global installs while logged in as root, rather than using sudo.

Resources