alpacahq / alpaca-ts

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

Remove file extension from imports to allow for multi-target builds #82

Closed jdgriffith closed 2 years ago

jdgriffith commented 2 years ago

I'm not 100% sure this is the issue with compilation/transpilation for Jest but seems like a good starting point. I don't believe you can hard code .js here and have it work for all scenarios. I know TS and javascript can handle module resolution without the file extension and assuming any build target can handle this resolution.

I had to bring in your project as a git submodule to get my tests working again. FYI - the types and documentation are great!

117 commented 2 years ago

Will try this fix.

117 commented 2 years ago

Still getting this error when testing against this repo alpaca-jest-issue.

 FAIL  ./index.spec.ts
  ● Test suite failed to run
    Jest encountered an unexpected token
    This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

    SyntaxError: Unexpected token 'export'

    > 1 | import { AlpacaClient } from "@master-chief/alpaca";
        | ^
      2 |
      3 | export const client = new AlpacaClient({
      4 |     credentials: {

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
      at Object.<anonymous> (index.ts:1:1)

Test Suites: 1 failed, 1 total

Haha now you got me down the rabbit hole again researching this further.. 😆

117 commented 2 years ago

I will leave this change though, thank you for the PR!

jdgriffith commented 2 years ago

Well bum! Was hoping this was part of the fix. I noticed all tests passed locally.