Webstorm Import url issues with Angular 2 - node.js

Looking for some guidance on WebStorm v11 and using Angular2 imports, I'm also on a Mac.
Whenever I am creating a component and I import for example Http service from Angular 2, WebStorm does its thing and automatically imports it on the page for me. However the URL for the import is a crazy string, but in all the demos I've seen it just imports to a simple string like this:
import {Http} from "angular2/core";
but mine will import like this:
import {Http} from "../../../node_modules/angular2/src/http/http";
So I will manually go and change it to the more simple one for readability and it still works fine. Any ideas or help on how I could get it to import with the simple string?

Related

Vite and dealing with require vs import (for google api)

First time using Vite with google apis and right at the start ran into trouble trying to import the translation client. It uses 'require' to import it const {TranslationServiceClient} = require('#google-cloud/translate') instead of 'import' syntax. I've tried workarounds including the vite require plugin but nothing has worked (reworking it into an import statement causes different errors with 'process not defined' which just stumped me even more) and it seems strange that no one else seems to mention any problem with vite and google apis. Has anyone run into this issue?
Did you try?
import TranslationServiceClient from "#google-cloud/translate";

import twilio's Authy library in nest js

we usually use below statement to use authy library in node file using js ,mostly by require statement !
const authy = require('authy')('API KEY');
I've moved my code to nest eco system and now How should i do the same using typescript ,as i also want to pass API Key to it ?
I've tried below code as well ,but still it's not working
import { authy } from 'authy'(API KEY)
suggest something !
I have faced a similar issue in my NestJS project when using twillio library.
Currently, I have resolved this by importing it this way:
import authy = require('authy');
If, this doesn't work for you (for any reason e.g. TypeScript compile error), then can you try the following import statement?
import * as Authy from 'authy';
Also, let me know which one works for you.

Secondary import when using Firebase?

Why do we need to import what seems like the same module twice when using Firebase?
import { firestore, initializeApp } from 'firebase';
import 'firebase/firestore';
Would be interesting to hear why this case may come up in general node/js es6 modules and not just here.
I usually do something like this:
import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';
The first line imports the main Firebase dependency, so that you call firebase.initializeApp(...).
The second and third line then import specific Firebase product SDKs on top of that, so that you can access firebase.firestore() and firebase.auth().
This pulls in the minimal amount of JavaScript that is needed for my specific app.
Your first line pulls in the SDKs for all Firebase projects, and then imports a few objects out of there. This is quite wasteful, as you're unlikely to be using all products in an app.
I'm actually not sure what the second line does in your case.

VSCode automatically breaking paths in Node.js app

All of a sudden VSCode has decided to automatically break my Node app paths. It's changing this line in server.ts:
import app from './app';
to this version which doesn't work:
import app from 'app';
It also wants to change other paths. For example:
import myCtrl = require('../controllers/my');
to the broken:
import myCtrl = require('controllers/my');
Is this some kind of IDE configuration vs app config conflict? I've looked but I can't find the issue.
Edit: It's changing about 12-15 files, so it's not just a quick undo. I have to check which changes I can just discard.
I don't want to just turn off the update imports paths options since it was useful. I have it on prompt right now but I can't use it because of this issue.

Importing Algorthmia into React-Native but receiving "Module does not exist..." error

I'm trying to include the Algorithmia client into my React-Native application and for some reason I keep hitting a "Module does not exist in the module map" error. I've followed the suggestions in the error and have Cleared Watchman watches, deleted and reinstalled node_modules, Reset Metro Bundler Cache and Removed the haste cache and still no luck.
Is there something I'm overlooking or unaware of?
I followed steps for installation from the Algorithmia docs
npm install --save algorithmia
and at the top of my AlgoComponent.js
import React, { Component } from 'react';
import { View, StyleSheet, Image, Dimensions, TouchableHighlight, Text } from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
import Algorithmia from 'algorithmia';
other styles i've tried:
import * as Algorithmia from 'algorithmia';
import { Algorithmia } from 'algorithmia';
I've looked around quite a bit, but so far no luck. Any suggestions would be greatly appreciated!
Update: 1/16/2018 - I didn't quite grasp that React-Native isn't truly node, since it's compiling to Objective C and Swift (might not have said that exactly right, but thats the gist). Maybe this is the issue I'm hitting since I was following the node docs? In the meantime I've set up an express server that will sit between my Native App and Firebase and am planning to make the calls to Algorithmia from there. I'll update as I get further along.
Final Update: 3/19/2018 - Unless another way opens up, I've decided to continue using the express server routing I set up in January. Seems to be working just fine.

Resources