Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Does not compile with TypeScript 4.7 module = nodenext #106

Open
vitalets opened this issue Jun 14, 2022 · 26 comments
Open

Does not compile with TypeScript 4.7 module = nodenext #106

vitalets opened this issue Jun 14, 2022 · 26 comments
Assignees
Labels
bug Something isn't working

Comments

@vitalets
Copy link

Description
Can't compile TypeScript project using @master-chief/alpaca with module = nodenext in tsconfig.json.

Expected
TypeScript compilation pass.

Reproduction

  1. Install latest TypeScript (4.7.3)
  2. Install latest @master-chief/alpaca (6.3.20): npm i @master-chief/alpaca
  3. Create tsconfig with module=NodeNext:
    "compilerOptions": {
      "target": "es2020",
      "module": "NodeNext",
      "strict": true,
      "allowSyntheticDefaultImports": true,
      "esModuleInterop": true
    },
  4. Create index.ts importing alpaca stuff:
    import { AlpacaClient, AlpacaStream } from '@master-chief/alpaca';
  5. Try to compile TypeScript: tsc

Logs

error TS7016: Could not find a declaration file for module '@master-chief/alpaca'. '.../node_modules/@master-chief/alpaca/dist/mjs/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/master-chief__alpaca` if it exists or add a new declaration (.d.ts) file containing `declare module '@master-chief/alpaca';`
@vitalets vitalets added the bug Something isn't working label Jun 14, 2022
@117
Copy link
Contributor

117 commented Jun 14, 2022

Will investigate.

@WinstonNau
Copy link

I have the same problem. A hotfix or a workaround, would be really appreciated! 😄

@WinstonNau
Copy link

I have the same problem. A hotfix or a workaround, would be really appreciated! 😄

Error:
grafik

@117
Copy link
Contributor

117 commented Jun 19, 2022

been busy 😢 ill try today

@117
Copy link
Contributor

117 commented Jun 19, 2022

well a temporary workaround would be

// @ts-ignore
import { AlpacaClient } from "@master-chief/alpaca";

and im able to compile with

{
  "compilerOptions": {
    "target": "es2020",
    "module": "NodeNext",
    "strict": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true
  }
}

@117
Copy link
Contributor

117 commented Jun 19, 2022

You can also do..

{
  "compilerOptions": {
    ...
    "noImplicitAny": false,
  }
}

@117
Copy link
Contributor

117 commented Jun 19, 2022

I don't know why its unable to find the typings, something to do with the way typescript ^4.8.0-dev.20220619 handles resolution? If I may ask why are you using the nightly version of typescript anyways? It is designated as unstable.

@117
Copy link
Contributor

117 commented Jun 19, 2022

Hmm trying one more thing.

@117
Copy link
Contributor

117 commented Jun 19, 2022

Yeah idk. Works fine on every non-dev typescript version for me.

@WinstonNau
Copy link

WinstonNau commented Jun 20, 2022

Yeah idk. Works fine on every non-dev typescript version for me.

Hmmm interesting. I was using TypeScript version 4.7.3 there and got the error. I tried installing the 4.6.3 version and still got the same error.

"compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "preserve"
  },

@117
Copy link
Contributor

117 commented Jun 20, 2022

@WinstonNau ill try

@vitalets
Copy link
Author

vitalets commented Jun 21, 2022

@117 Maybe the reason is that dist/cjs/*.cjs files are looking for typings in @types/*.d.cts files (not in @types/*.d.ts)? One idea is instead of renaming dist/cjs/*.js -> dist/cjs/*.cjs generate simple package.json in dist/cjs:

{"type":"commonjs"}

@117
Copy link
Contributor

117 commented Jun 22, 2022

will try this!

@WinstonNau
Copy link

@WinstonNau ill try

Thank you! Let me know if you might have a fix for this problem :)

@117
Copy link
Contributor

117 commented Jun 23, 2022

oh my god .d.cts works

@117
Copy link
Contributor

117 commented Jun 23, 2022

i'm going to write a new build script and config which generates the new declarations tomorrow. too tired right now

@117
Copy link
Contributor

117 commented Jun 24, 2022

delaying another day 😞 work is kicking my ass

@117
Copy link
Contributor

117 commented Jun 24, 2022

Ok! Before I publish it please test and let me know if this solves it for you. Try npm i 117/alpaca and let me know :)

  "dependencies": {
    "@master-chief/alpaca": "github:117/alpaca"
  },

I have tested this personally with the following tsconfig.

{
  "compilerOptions": {
    "target": "es2020",
    "module": "NodeNext",
    "strict": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true
  }
}

@WinstonNau @vitalets

@vitalets
Copy link
Author

@117 does not compile for me :(

npx tsc

node_modules/@master-chief/alpaca/dist/cjs/index.d.cts:10:353 - error TS2307: Cannot find module './entities' or its corresponding type declarations.

10 export { Account, Order, OrderCancelation, Position, Asset, Watchlist, Calendar, Clock, DefaultCredentials, OAuthCredentials, AccountConfigurations, NonTradeActivity, TradeActivity, Activity, PortfolioHistory, Bar, Bar_v1, Quote, LastQuote_v1, LastTrade_v1, Trade, PageOfBars, PageOfQuotes, PageOfTrades, Snapshot, DataSource, Channel, Message, } from './entities';
                                                                                                                                                                                                                                                                                                                                                                   ~~~~~~~~~~~~

node_modules/@master-chief/alpaca/dist/cjs/index.d.cts:11:449 - error TS2307: Cannot find module './params' or its corresponding type declarations.

11 export { GetOrder, GetOrders, PlaceOrder, ReplaceOrder, CancelOrder, GetPosition, ClosePosition, GetAsset, GetAssets, GetWatchList, CreateWatchList, UpdateWatchList, AddToWatchList, RemoveFromWatchList, DeleteWatchList, GetCalendar, UpdateAccountConfigurations, GetAccountActivities, GetPortfolioHistory, GetBars, GetBars_v1, GetTrades, GetQuotes, GetSnapshot, GetSnapshots, GetLastTrade_v1, GetLastQuote_v1, BarsV1Timeframe, BarsTimeframe, } from './params';
                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ~~~~~~~~~~

node_modules/@master-chief/alpaca/dist/cjs/stream.d.cts:1:23 - error TS2688: Cannot find type definition file for 'ws'.

1 /// <reference types="ws" />
                        ~~

node_modules/isomorphic-ws/index.d.ts:6:28 - error TS7016: Could not find a declaration file for module 'ws'. '/Users/vitalets/projects/tmp/node_modules/ws/index.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/ws` if it exists or add a new declaration (.d.ts) file containing `declare module 'ws';`

6 import WebSocket = require('ws')
                             ~~~~


Found 4 errors in 3 files.

Errors  Files
     2  node_modules/@master-chief/alpaca/dist/cjs/index.d.cts:10
     1  node_modules/@master-chief/alpaca/dist/cjs/stream.d.cts:1
     1  node_modules/isomorphic-ws/index.d.ts:6

Environment:
npm ls

tmp@1.0.0 /projects/tmp
├── @master-chief/alpaca@6.3.20 (git+ssh://git@github.com/117/alpaca.git#79a216be9073b01587b2bc599919275bbaa28797)
└── typescript@4.7.4

cat tsconfig.json

{
  "compilerOptions": {
    "target": "es2020",
    "module": "NodeNext",
    "strict": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "noEmit": true,
  },
  "include": [ "src" ]
}

node -v

v16.14.0

@WinstonNau
Copy link

WinstonNau commented Jun 25, 2022

I get this error in WebStorm

grafik

and this error after starting the app:

grafik

and this is my tsconfig (the module automatically changes to esnext so I can't use NodeNext)

grafik

@vitalets
Copy link
Author

Hi @117!
Any update on this issue? =)

@117
Copy link
Contributor

117 commented Jul 28, 2022

no update ):

@117 117 linked a pull request Apr 6, 2023 that will close this issue
Closed
@117
Copy link
Contributor

117 commented Apr 6, 2023

v7 is on the way, you can track it here #113

@bennycode
Copy link

I also received error TS7016 when trying to use @master-chief/alpaca v6.3.20 in a TS project using ESM with moduleResolution set to node16 and module set to es2022. Upgrading to @master-chief/alpaca-ts v7.0.9-alpha solved the issue for me! 👍

@bennycode
Copy link

@117 I also tried "@master-chief/alpaca": "github:117/alpaca". It works when I set "skipLibCheck" to true in my TS config. Given that this library is currently the best solution for TS-ESM projects (as it is executable and provides typings), can you make a release from it?

@bennycode
Copy link

Hey @117, today I noticed that the error callback of stream.ts is typed wrongly:

error: (message: WebSocket.ErrorEvent) => void;

Instead of a WebSocket.ErrorEvent a custom error in the format of { T: 'error', code: 406, msg: 'connection limit exceeded' } is returned. I made a PR for it: #118

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants