Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A problem with cd outside the project #1157

Closed
cvecina opened this issue Apr 17, 2024 · 3 comments
Closed

A problem with cd outside the project #1157

cvecina opened this issue Apr 17, 2024 · 3 comments

Comments

@cvecina
Copy link

cvecina commented Apr 17, 2024

Node version (or tell us if you're using electron or some other framework):

Using Nuxt 3 - node version v21.6.2

ShellJS version (the most recent version/Github branch you see the bug on):

0.8.5

Operating system:

Mac OS 14.4.1 (23E224) (Sonoma)

Description of the bug:

I'm trying to cd to the home directory (using 'os' library) and list the data (ls -l) and i get this error:

ERROR cd: not a directory: /Users/razor

and the ls -l command is executed on the project folder.

is possible to cd to another folder outside the project?

Example ShellJS command to reproduce the error:

import os from "os";
import shell from "shelljs";

const homedir = os.homedir();

const listarArchivosDeCarpeta = async () => {
shell.cd(homedir);
shell.exec("ls -l");
}

export default defineEventHandler(async (event) => {
await listarArchivosDeCarpeta();
})

@cvecina
Copy link
Author

cvecina commented Apr 17, 2024

i tried to create with mkdir using shell.mkdir and cd it, and i can't cd inside the project too.

example:

shell.mkdir('prueba')
shell.cd('prueba')
shell.exec('ls -l')

the ls -l works correctly on main folder, it shows that exists the new 'prueba', but the cd returns the same error. ERROR cd: not a directory: /prueba

@nfischer
Copy link
Member

What is nuxt 3?

Can you try this in plain old nodejs? shell.cd() is supposed to work for basically any folder—as long as you have permission to enter that folder, shell.cd() should handle it.

@nfischer
Copy link
Member

nfischer commented May 7, 2024

I think this is a problem caused by nuxt, so it is not something we can workaround. "In development, [nuxt] uses... workers." This is a known limitation of workers and it's not something we can workaround: "process.chdir() and process methods that set group or user ids are not available".

If process.chdir() is not allowed, then shell.cd() simply cannot ever work. You should find a way to workaround this on your end.

@nfischer nfischer closed this as not planned Won't fix, can't repro, duplicate, stale May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants