alpacahq / alpaca-ts

A TypeScript Node.js library for the https://alpaca.markets REST API and WebSocket streams.
ISC License
154 stars 42 forks source link

I can't get the module to compile within a Typescript node project #68

Closed awweather closed 3 years ago

awweather commented 3 years ago

Hi,

I have a typescript node project. I've used NPM to install the module.

Using import { AlpacaClient, AlpacaStream } from "@master-chief/alpaca"; gives me the error below:

image

It appears it's trying to use the index.js from the dist/mjs folder, although my module config in compiler options is set to use commonjs. Any idea on how I can get this working? Should I be using one of the bundles?

117 commented 3 years ago

What version of node?

117 commented 3 years ago

To run my code I'm also using ts-node:

node --loader ts-node/esm src/main.ts

Snippet from my package.json:

"type": "module",
"dependencies": {
  "@master-chief/alpaca": "^6.1.2"
}

My node version is v14.7.0 but unlike you I do not use commonjs for my compilerOptions, I use esnext. If you wish to use commonjs you can import a direct path to the dist/cjs/index.js folder or one of the bundles.

117 commented 3 years ago

I should probably showcase different styles of imports on the README thank you for opening the issue.

awweather commented 3 years ago

Good call, I was on an older version of node. Updated to the most recent stable and it's working now.

awweather commented 3 years ago

Sorry for the confusion! But maybe it'll help someone that runs into a similar issue