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

fix(core): update ensurePackage util with workaround for bad module cache #14786

Merged
merged 1 commit into from
Feb 7, 2023

Conversation

jaysoo
Copy link
Member

@jaysoo jaysoo commented Feb 3, 2023

The current ensurePackage function from @nrwl/devkit fails for some packages like typescript due to bad module cache (Note: not require cache, but module/file cache).

See the problem here: https://github.com/jaysoo/ts-resolve-pkg

The solution is to avoid require.resolve or require when detecting the locally installed package version. Instead, use a sandboxed require from createRequire(...) to avoid any pollution.

Current Behavior

await ensurePackage(tree, 'typescript')
await import(`typescript`) // fails

Expected Behavior

await ensurePackage(tree, 'typescript')
await import(`typescript`) // works

Related Issue(s)

Fixes #

@vercel
Copy link

vercel bot commented Feb 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
nx-dev ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Feb 7, 2023 at 7:59PM (UTC)

@jaysoo jaysoo force-pushed the fix/ensure-package-typescript branch from b406d7a to 503f5e6 Compare February 3, 2023 14:30
@jaysoo jaysoo force-pushed the fix/ensure-package-typescript branch from 503f5e6 to 4edbe76 Compare February 3, 2023 14:44
@jaysoo jaysoo force-pushed the fix/ensure-package-typescript branch from 4edbe76 to 57e2d1f Compare February 3, 2023 16:43
@jaysoo jaysoo force-pushed the fix/ensure-package-typescript branch from 57e2d1f to 314331c Compare February 3, 2023 16:47
@jaysoo jaysoo force-pushed the fix/ensure-package-typescript branch from 314331c to fc22ccc Compare February 3, 2023 17:08
@jaysoo jaysoo force-pushed the fix/ensure-package-typescript branch from fc22ccc to b71c118 Compare February 3, 2023 18:51
@jaysoo jaysoo force-pushed the fix/ensure-package-typescript branch from b71c118 to c3f048f Compare February 3, 2023 19:14
@jaysoo jaysoo force-pushed the fix/ensure-package-typescript branch from c3f048f to 8edd29f Compare February 7, 2023 19:23
@FrozenPandaz FrozenPandaz merged commit fc20e69 into nrwl:master Feb 7, 2023
@jaysoo jaysoo deleted the fix/ensure-package-typescript branch February 7, 2023 21:21
@github-actions
Copy link

github-actions bot commented Mar 3, 2023

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants