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

Path *** is not in cwd *** #133

Open
fjc0k opened this issue Jul 17, 2019 · 12 comments
Open

Path *** is not in cwd *** #133

fjc0k opened this issue Jul 17, 2019 · 12 comments

Comments

@fjc0k
Copy link

fjc0k commented Jul 17, 2019

Just running this code:

const paths = await globby(
 '../src/*.ts',
  {
    dot: true,
    onlyFiles: false,
    gitignore: true,
    cwd: __dirname,
    absolute: true,
  },
)

Then you will get an error:

Path *** is not in cwd ***

But if you set gitignore to false, all works well.

After a bit of investigation, most likely it is caused by this PR: #120

@jaydenseric
Copy link

I'm seeing this error too, when trying to use an glob containing an absolute os.tmpdir() path with { gitignore: true }.

Absolute temp dir paths are very useful in tests.

@rwjblue
Copy link
Contributor

rwjblue commented Oct 16, 2019

#137 fixes at least some of the scenarios where this error is being thrown, though it isn't clear if it is all of them.

@sindresorhus
Copy link
Owner

@fjc0k Can you try out https://github.com/sindresorhus/globby/releases/tag/v10.0.2 and let us know if that fixes your issue?

@fjc0k
Copy link
Author

fjc0k commented Jan 6, 2020

@sindresorhus No, always the same error for each version:

10.0.0, 10.0.1, 10.0.2, 11.0.0:

image

@nzakas
Copy link
Contributor

nzakas commented Mar 12, 2020

I'm also seeing a version of this issue. In my case, it seems to be caused by my being on Windows, so the absolute path being checked and the cwd are not in the same format. That means using startsWith() to check the two paths doesn't work (https://github.com/sindresorhus/globby/blob/master/gitignore.js#L48) (and I would expect would cause other errors).

The error I'm getting:

Path C:/Users/Nicholas/Documents/projects/nitpik/cli/nitpik.config.js is not in cwd C:\Users\Nichol
as\Documents\projects\nitpik\cli

@nzakas
Copy link
Contributor

nzakas commented May 26, 2020

I opened a PR to at least solve the issue in Windows I was seeing:
#143

I'm not sure if it helps with other use cases, too.

@navoneel07
Copy link

I'm seeing this error too, when trying to use an glob containing an absolute os.tmpdir() path with { gitignore: true }.

Absolute temp dir paths are very useful in tests.

@jaydenseric did you ever get around this error? (I know I'm asking a whole year late :P)

@jaydenseric
Copy link

@navoneel07 I can't remember anything about this problem, sorry!

@BasixKOR
Copy link

BasixKOR commented Nov 3, 2020

I just encountered this error on @yarnpkg/doctor. It seems like this error is still happening in v11.0.1.

@CaoMeiYouRen
Copy link

It could be a solution.

// gitignore.js#48
const ensureAbsolutePathForCwd = (cwd, p) => {
+	p = path.normalize(p);
	cwd = slash(cwd);
	if (path.isAbsolute(p)) {
		if (p.startsWith(cwd)) {
			return p;
		}

		throw new Error(`Path ${p} is not in cwd ${cwd}`);
	}

	return path.join(cwd, p);
};

@jjangga0214
Copy link

jjangga0214 commented Jul 27, 2022

@sindresorhus Hi!
I haven't tested but it seems this issue might be simply solved by @CaoMeiYouRen's solution.
Would you fix this and publish a new version?
Thank you very much.

P.S. I am using ^11 as I cannot depend on a pure ESM module, yet. I hope you publish a bugfix version for 11 as well. Maintaining the last CJS version and the latest ESM version simultaneously would be great for people who really cannot move on to ESM right now for a while.

@fisker
Copy link
Collaborator

fisker commented Nov 17, 2022

ignore bring the old(v4) behavior back by adding allowRelativePaths options, maybe we should consider use that. kaelzhang/node-ignore@052a722

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants