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

typescript: Cannot find module 'tslib' #1262

Closed
benfoxall opened this issue Oct 29, 2024 · 3 comments · Fixed by #1264
Closed

typescript: Cannot find module 'tslib' #1262

benfoxall opened this issue Oct 29, 2024 · 3 comments · Fixed by #1264
Labels
bug Something isn't working

Comments

@benfoxall
Copy link

Description

When importing @mcap/nodejs (and other packages), I'm getting an error Cannot find module 'tslib'.

  • Version: v22.10.0
  • Platform: macOS

Steps To Reproduce

Create a minimal package.json:

{
  "dependencies": {
    "@mcap/nodejs": "^1.0.1"
  }
}

Install dependencies and import module

npm install
node -e "require('@mcap/nodejs')"

Expected Behavior

😎

Actual Behavior

node -e "require('@mcap/nodejs')"
node:internal/modules/cjs/loader:1252
  throw err;
  ^

Error: Cannot find module 'tslib'
Require stack:
- /Users/ben/tmp/mcap/node_modules/@mcap/nodejs/dist/cjs/src/index.js
- /Users/ben/tmp/mcap/[eval]
    at Function._resolveFilename (node:internal/modules/cjs/loader:1249:15)
    at Function._load (node:internal/modules/cjs/loader:1075:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1340:12)
    at require (node:internal/modules/helpers:141:16)
    at Object.<anonymous> (/Users/ben/tmp/mcap/node_modules/@mcap/nodejs/dist/cjs/src/index.js:3:17)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Object..js (node:internal/modules/cjs/loader:1689:10)
    at Module.load (node:internal/modules/cjs/loader:1318:32) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/ben/tmp/mcap/node_modules/@mcap/nodejs/dist/cjs/src/index.js',
    '/Users/ben/tmp/mcap/[eval]'
  ]
}

Node.js v22.10.0

Additional information

The contents of node_modules/@mcap/nodejs/dist/cjs/src/index.js imports tslib for the __exportStar helper.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
tslib_1.__exportStar(require("./FileHandleReadable"), exports);
tslib_1.__exportStar(require("./FileHandleWritable"), exports);
//# sourceMappingURL=index.js.map

This looks like it's been added by the importHelpers option, which is present in the base foxglove/tsconfig.

It'd be great if tslib was a dependency, or the helpers were inlined?

Workaround

Installing tslib separately will resolve this issue.

npm install tslib
@benfoxall benfoxall added the bug Something isn't working label Oct 29, 2024
Copy link

linear bot commented Oct 29, 2024

@benfoxall benfoxall changed the title [typescript] Cannot find module 'tslib' typescript: Cannot find module 'tslib' Oct 29, 2024
@jtbandes
Copy link
Member

🤔 you might be right that there's a missing dependency. However, @mcap/core does declare a dependency on tslib, so I'd expect things to work if you also have @mcap/core installed:

"tslib": "^2.5.0"

@benfoxall
Copy link
Author

@jtbandes oh yep that might help. I think in my case I may have had an additional monorepo/package-hoisting issue where core/nodejs were separated 😬

jtbandes added a commit that referenced this issue Oct 30, 2024
### Changelog
TypeScript: Added missing dependencies on `tslib`

### Docs

None

### Description

Fixes #1262

When `importHelpers` is true in tsconfig.json (as it is by default with
`@foxglove/tsconfig`), `tslib` must be a dependency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

2 participants