Skip to content

Conversation

@targos
Copy link
Member

@targos targos commented Dec 21, 2024

On macOS, os.tmpdir() returns a path that contains a symbolic links.
This can cause issues with modules that expect the environment to only
contain real paths. For example, the resolve module uses the HOME env
variable, which is derived from the context's path.

Example of fixed error:
error: error:              | not ok 450 sanity check: require.resolve finds HNM `baz`
error:                     | ---
error:                     | operator: equal
error:                     | expected: |-
error:                     | '/var/folders/9n/05y6s4ls78515vmnbd86hktm0000gn/T/fc57c0d4-4128-4194-8fb0-f862577957ef/home/.node_modules/baz/quux.js'
error:                     | actual: |-
error:                     | '/private/var/folders/9n/05y6s4ls78515vmnbd86hktm0000gn/T/fc57c0d4-4128-4194-8fb0-f862577957ef/home/.node_modules/baz/quux.js'
error:                     | at: <anonymous> (/private/var/folders/9n/05y6s4ls78515vmnbd86hktm0000gn/T/fc57c0d4-4128-4194-8fb0-f862577957ef/resolve/test/home
error:                     | stack: |-
error:                     | Error: sanity check: require.resolve finds HNM `baz`
error:                     | at Test.assert [as _assert] (/private/var/folders/9n/05y6s4ls78515vmnbd86hktm0000gn/T/fc57c0d4-4128-4194-8fb0-f862577957ef/resol
error:                     | at Test.strictEqual (/private/var/folders/9n/05y6s4ls78515vmnbd86hktm0000gn/T/fc57c0d4-4128-4194-8fb0-f862577957ef/resolve/node_
error:                     | at /private/var/folders/9n/05y6s4ls78515vmnbd86hktm0000gn/T/fc57c0d4-4128-4194-8fb0-f862577957ef/resolve/test/home_paths_sync.js
error:                     | at /private/var/folders/9n/05y6s4ls78515vmnbd86hktm0000gn/T/fc57c0d4-4128-4194-8fb0-f862577957ef/resolve/test/home_paths_sync.js
error:                     | at /private/var/folders/9n/05y6s4ls78515vmnbd86hktm0000gn/T/fc57c0d4-4128-4194-8fb0-f862577957ef/resolve/node_modules/mkdirp/ind
error:                     | at FSReqCallback.oncomplete (node:fs:189:23)
error:                     | ...

On macOS, `os.tmpdir()` returns a path that contains a symbolic link.
This can cause issues with modules that expect the environment to only
contain real paths. For example, the `resolve` module uses the HOME env
variable, which is derived from the context's path.
@targos targos marked this pull request as draft December 21, 2024 11:23
@targos targos marked this pull request as ready for review December 21, 2024 11:49
@targos targos merged commit 6ea2d7b into nodejs:main Dec 23, 2024
14 checks passed
@targos targos deleted the symlink branch December 23, 2024 08:41
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