amplitude / Amplitude-Node

Server-side Node.js SDK for Amplitude
MIT License
67 stars 20 forks source link

Error: Cannot find module 'tslib' (on require) #4

Closed ChaseWagoner closed 4 years ago

ChaseWagoner commented 4 years ago

Firstly, thank you for publishing a Node SDK! I greatly appreciate it.

When requiring @amplitude/node, I see Error: Cannot find module 'tslib'.

Environment setup:

$ node --version
v10.14.1
$ npm --version
6.14.5
$mkdir test && cd test
$ npm init
# I used all default suggested values
$ npm install --save @amplitude-node
$ node
# In the Node.js REPL:
> require('@amplitude/node')
{ Error: Cannot find module 'tslib'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:580:15)
    at Function.Module._load (internal/modules/cjs/loader.js:506:25)
    at Module.require (internal/modules/cjs/loader.js:636:17)
    at require (internal/modules/cjs/helpers.js:20:18) code: 'MODULE_NOT_FOUND' }

I did not find any direct references to tslib in src/, but I did some investigation after cloning Amplitude-Node:

Amplitude-Node $ npm ls tslib
@amplitude/node@0.1.0 .../packages/Amplitude-Node
├─┬ @typescript-eslint/eslint-plugin@2.30.0
│ └─┬ tsutils@3.17.1
│   └── tslib@1.11.1 
└─┬ eslint@6.8.0
  └─┬ inquirer@7.1.0
    └─┬ rxjs@6.5.5
      └── tslib@1.11.1  deduped

The top-level packages using tslib are only devDependencies, so tslib would not be published with @amplitude/node. I wondered why tslib was used by the built package:

Amplitude-Node $ npm run build

dist/nodeClient.js contains the following:

var NodeClient = /** @class */ (function (_super) {
    tslib_1.__extends(NodeClient, _super);

I don't know which compiler/tsconfig settings cause tslib to be used for extends in the distributed code, but I have found a workaround: in my project that uses @amplitude/node, I also install tslib as a dependency. That resolves the error, at least short-term. Long-term, in @amplitude/node itself, I don't know if it's the best way to solve the error, but I have found one workable solution: merely adding tslib to dependencies does seem to fix the issue.

haoliu-amp commented 4 years ago

Thank you for such detail issue report! We greatly appreciated it and welcome our 1st user! I just added tslib into our dependency. You can bump the version to 0.2.0 to see if it works.

ChaseWagoner commented 4 years ago

I've updated to 0.2.0, and the issue seems to be resolved. Thanks @haoliu-amp.