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

npm-compat: ts-results issues #22806

Closed
sigmaSd opened this issue Mar 8, 2024 · 3 comments
Closed

npm-compat: ts-results issues #22806

sigmaSd opened this issue Mar 8, 2024 · 3 comments
Labels
invalid what appeared to be an issue with Deno wasn't

Comments

@sigmaSd
Copy link
Contributor

sigmaSd commented Mar 8, 2024

Version: Deno 1.41.2

// import { Err, Ok, Result } from "https://esm.sh/[email protected]"; // works
import { Err, Ok, Result } from "npm:[email protected]"; // fails

console.log(Result.wrap(() => Deno.readTextFileSync("/etc/hostsz")));

error

error: Uncaught (in promise) Error: Cannot find module 'tslib'

also note the npm package tries to read the node_modules dir when used with npm:, while using it from esm doesn't do this (so no need to give read all permission)

image

@dsherret
Copy link
Member

dsherret commented Mar 8, 2024

The exact same error happens in Node:

> node main.js
node:internal/modules/cjs/loader:1152
  throw err;
  ^

Error: Cannot find module 'tslib'
Require stack:
- V:\scratch\node_modules\ts-results\index.js
- V:\scratch\main.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1149:15)
    at Module._load (node:internal/modules/cjs/loader:990:27)
    at Module.require (node:internal/modules/cjs/loader:1237:19)
    at require (node:internal/modules/helpers:176:18)
    at V:\scratch\node_modules\ts-results\index.js:12:19
    at V:\scratch\node_modules\ts-results\index.js:3:17
    at Object.<anonymous> (V:\scratch\node_modules\ts-results\index.js:9:3)
    at Module._compile (node:internal/modules/cjs/loader:1378:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1437:10)
    at Module.load (node:internal/modules/cjs/loader:1212:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'V:\\scratch\\node_modules\\ts-results\\index.js',
    'V:\\scratch\\main.js'
  ]
}

Node.js v21.6.1

It's because ts-results uses the tslib package, but doesn't define it as a dependency (which it should).

This bug was fixed in this PR, but they never did a release: vultix/ts-results#38

To get around this, you can use a node_modules directory and also import the tslib package. That will cause tslib to exist in the node_modules folder, which will allow ts-results to work properly.

@dsherret dsherret added the invalid what appeared to be an issue with Deno wasn't label Mar 8, 2024
@sigmaSd
Copy link
Contributor Author

sigmaSd commented Mar 8, 2024

I see thanks

@sigmaSd sigmaSd closed this as completed Mar 8, 2024
@ry
Copy link
Member

ry commented Mar 10, 2024

See also https://jsr.io/@oxi/result

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid what appeared to be an issue with Deno wasn't
Projects
None yet
Development

No branches or pull requests

3 participants