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

Does not work with Angular 11 #153

Closed
whoiscarlo opened this issue Apr 30, 2021 · 5 comments
Closed

Does not work with Angular 11 #153

whoiscarlo opened this issue Apr 30, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@whoiscarlo
Copy link

whoiscarlo commented Apr 30, 2021

Bug Report

Describe the bug

Error: node_modules/yahoo-finance2/api/index-common.d.ts:1:8 - error TS1259: Module '"/Users/darknyte/Dropbox/Sandbox/angular/lucrative/node_modules/yahoo-finance2/api/lib/yahooFinanceFetch"' can only be default-imported using the 'allowSyntheticDefaultImports' flag

1 import yahooFinanceFetch from "./lib/yahooFinanceFetch";
         ~~~~~~~~~~~~~~~~~

  node_modules/yahoo-finance2/api/lib/yahooFinanceFetch.d.ts:1:1
    1 export = yahooFinanceFetch;
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    This module is declared with using 'export =', and can only be used with a default import when using the 'allowSyntheticDefaultImports' flag.

Minimal Reproduction

Create a brand new angular project

ng new yahoo-test
install yahoo-finance2:
npm i yahoo-finance2

In app.component.ts
add import yahooFinance from 'yahoo-finance2';
Save file
Then run ng serve

Repo Link

Environment

Node version : v15.4.0
Npm version: 7.11.2
Angular: 11.0.5
Typescript: 4.0.2
TS Lint: 6.1.0
TS-Node: 8.3.0

@whoiscarlo whoiscarlo added the bug Something isn't working label Apr 30, 2021
@gadicc
Copy link
Owner

gadicc commented May 2, 2021

Hey @whoiscarlo, thanks for reporting.

I don't have any experience with Angular but this seems to be a TypeScript error, so not sure why we haven't noticed it before. Looking at the typescript docs for allowSyntheticDefaultImports, it sounds like you can either set this option to true in your tsconfig.json or perhaps try:

import * as yahooFinance from "yahoo-finance2"

I'll note also that we're busy working on better module support in #144, which will probably land later this week or next week, which should result in you being able to import yahoo-finance2 like normal and without any special flags. (Also, importing as in the above might break when this lands, so changing the config option (temporarily) is probably a safer bet).

Please leave this issue open and we'll update when the above code is merged and released.

@gadicc
Copy link
Owner

gadicc commented May 2, 2021

Oh and, on another note, this package (and the original) aren't well suited for running in the browser. We made sure in this release to make sure it can be loaded in the browser, but network requests to Yahoo's servers will be blocked by CORS, and you'll need a proxy server to get around that. There's a small note about it in the README (on this repo). However, if you're using this server-side with Angular you'll be fine (I don't really know exactly how the ng build process works).

@whoiscarlo
Copy link
Author

whoiscarlo commented May 2, 2021

@gadicc dude you're the man!! Thanks for even taking the time to respond to this. I'll try out that solution and see how it goes.

I be honest and admit I didn't fully read the README as I should have 😓 and just dived, in so I'll be better with that next time. And as a completed noob developer I had no idea what a CORS error was or how to get around it, so after 2 days of messing around I built myself a small Go-Fiber rest api and started querying data from Yahoo's API directly 😅

@gadicc
Copy link
Owner

gadicc commented May 3, 2021

Great stuff, happy I could help. Sure, see how you go. And maybe it's not a bad idea for us to log a warning to the console when used in the browser, I've surely badly skimmed READMEs before in my time.

advaiyalad added a commit to advaiyalad/node-yahoo-finance2 that referenced this issue May 26, 2021
advaiyalad added a commit to advaiyalad/node-yahoo-finance2 that referenced this issue May 26, 2021
gadicc pushed a commit that referenced this issue Jun 1, 2021
# [1.11.0](v1.10.4...v1.11.0) (2021-06-01)

### Bug Fixes

* **deps:** update dependency ajv to ^8.1.0 ([1769641](1769641))
* **quoteCombine:** resolve `undefined` for missing symbols ([#150](#150)) ([f8c25e3](f8c25e3))
* **testing:** specify jest.js path, not bin ([#170](#170)) ([6772c8e](6772c8e))

### Features

* **options:** accept `date` option ([#186](#186)) ([11b8a72](11b8a72))
* add (friendly) warning when used in the browser ([3c4c5a0](3c4c5a0)), closes [#153](#153)
* add insights module ([#169](#169)) ([4603232](4603232))
* **concurrency:** ability to limit max simultaneous requests ([#76](#76)) ([3424d44](3424d44))
* **modules:** build (true) esm, (interop) cjs modules; tests/readme ([#144](#144)) ([2182f6c](2182f6c))
* **setGlobalConfig:** add setGlobalConfig function ([#133](#133)) ([43ebaa4](43ebaa4))
@gadicc
Copy link
Owner

gadicc commented Jun 1, 2021

Hey @whoiscarlo, I don't think you're actually still using node-yahoo-finance2 anymore, but just in case, the new module support (which has been in devel for a while) was just released (and @PythonCreator27 added an extra warning in the browser console that refers back to the README). I'm closing for now but in case you are still using this, please do report back :)

@gadicc gadicc closed this as completed Jun 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants