Skip to content

Problems with pnpm due to removal of realpath function #876

Description

@TorstenStueber

Issue #797 was resolved in commit 9691206 by removing the realpath option from the host service parameter for the TypeScript language server. However, this breaking change is not compatible with the package manager pnpm, which makes extensive use of symlinks in node_modules.

This is a simple example to reproduce this problem:

pnpm init -y
pnpm install --save ts-node typescript stellar-sdk @types/node 

Then create a file index.ts with the content:

import*asstellarfrom"stellar-sdk";console.log(stellar.Network);

The TypeScript compiler will run without any problems, i.e., executing the following command will finish successfully:

./node_modules/.bin/tsc index.ts --noEmit

However, when running

./node_modules/.bin/ts-node index.ts

then this will yield the error message:

TSError: ⨯ Unable to compile TypeScript:
2 console.log(stellar.Network);
~~~~~~~

Reason

The package stellar-sdk has another dependency stellar-base. The class Network is defined in stellar-base and re-exported by stellar-sdk. pnpm will structure node_modules as follows (arrows indicate symlinks):

node_modules
|
+-- stellar-sdk -> .registry.npmjs.org/stellar-sdk/2.3.0/node_modules/stellar-sdk
|
+-- .registry.npmjs.org
|
+-- stellar-sdk/2.3.0/node_modules
| |
| +-- stellar-base -> ../../../stellar-base/1.1.2/node_modules/stellar-base
| |
| +-- stellar-sdk (actual package content)
|
+-- stellar-base/1.1.2/node_modules
|
+-- stellar-base (actual package content)

When running ts-node the TypeScript language server is not able to load stellar-base as symlinks are not correctly resolved: TypeScript will first resolve the module name stellar-sdk found in index.ts to <project>/node_modules/stellar-sdk/lib/index.d.ts but then is unable to resolve the real path of this file (see here and here). When reading <project>/node_modules/stellar-sdk/lib/index.d.ts, it finds a reference to stellar-base and tries to resolve it but the module resolution algorithm will not be able to find a package stellar-base inside a node_modules folder that is a parent (or grandparent) directory of <project>/node_modules/stellar-sdk/lib/index.d.ts.

Observe that stellar-base can be found if <project>/node_modules/stellar-sdk/lib/index.d.ts is correctly resolved to <project>/node_modules/.registry.npmjs.org/stellar-sdk/2.3.0/node_modules/stellar-sdk/lib

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions