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

resolveCwd doesn't work when use ava from an npm linked project #2971

Closed
wants to merge 1 commit into from

Conversation

ailisp
Copy link

@ailisp ailisp commented Feb 17, 2022

A common senario:
Project A depends on ava. Project B depends on project A. In Project A, call npm link. In project B, call npm link ProjectA. Now in project B tests are broken because resolveCwd cannot find ts-node/register:

Error: Could not resolve required module ’ts-node/register’

However, nodejs's require can find it, and also require.resolve. And use require.resolve doesn't break in original setup of ava so i use require.resolve.

Also with console.log I noticed that this resolveModules only tries to resolve one module: ts-node/register. What is the purpose of this method?

A common senario:
Project A depends on ava. Project B depends on project A. In Project A, call `npm link`. In project B, call `npm link ProjectA`. Now in project B tests are broken because resolveCwd cannot find ts-node/register:
```
Error: Could not resolve required module ’ts-node/register’
```

However, nodejs's `require` can find it, and also `require.resolve`. And use `require.resolve` doesn't break in original setup of ava so i use `require.resolve`.

Also with `console.log` I noticed that this `resolveModules` only tries to resolve one module: `ts-node/register`. What is the purpose of this method?
@novemberborn
Copy link
Member

I think it's meant to resolve absolute paths to modules provided in AVA's require config. But I don't know whether that's still relevant, or whether this is the best way of going about it. I'll need to think about this.

@novemberborn
Copy link
Member

I think we should resolve relative to the project directory, likely we're trying to approximate that with resolve-cwd but the CWD doesn't have to be the project directory. I'd classify this as a bug, actually.

This is needed so that we import the expected module, without say AVA's dependencies shadowing it.

We may be able to use https://nodejs.org/api/module.html#modulecreaterequirefilename with the project directory and use the resolve() method on that.

But I don't know if that'll fix your issue.

@ailisp
Copy link
Author

ailisp commented Mar 2, 2022

Thanks @novemberborn! We used to have a wrapper of ava as project A. Recently we dropped project A, now Project B depends on ava directly and we're not blocked by the issue. You suggested https://nodejs.org/api/module.html#modulecreaterequirefilename looks like a valid fix

@novemberborn
Copy link
Member

Tracking in #2985.

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

Successfully merging this pull request may close these issues.

2 participants