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

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.

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";

Webpack with Next.js bundles file it is not supposed to in client bundle

I have a Next.js app with mongoose to connect to my mongodb. The models import db.ts to make sure that there is an active connection to the database like so:
import { model, models, Schema } from "mongoose";
import "../../db";
This is the code that connects to my database:
import mongoose from "mongoose";
mongoose.connect("mongodb://admin:admin#localhost:27022/admin");
I have gone ahead and made some serverless functions in next.js and added some database fetching from the models in my getServerSideProps. All of which worked perfectly fine. I can interact with the models, create new Documents, delete them and update them. there are no issues.
The Problem
I recently added a new component: it is at /pages/flashcards/[id].tsx. Just like my other components, this one imports one of my mongoose models. However, for some reason, Webpack feels like it should bundle the model and its import of ../../db and send it and send it over to the client, which results in this error:
TypeError: mongoose__WEBPACK_IMPORTED_MODULE_0___default(...).connect
is not a function
Again: This does not happen with any of my other components which use the exact same models as the component which is having these problems.
The issue occurs because you have the following unused import in the /pages/flashcards/[id] page.
import question from "../../db/models/question";
Any code inside getServerSideProps or getStaticProps, and imports used exclusively by these methods, is removed by Next.js when building the client bundle.
However, since question is not explicitly being used in getServerSideProps, Next.js can't figure out the import is only meant to be used on the server. This means it will be included in both the server and client bundles.
You can use the Next.js Code Elimination tool to verify what Next.js eliminates from the client-side bundle. You'll see that if you run your page's code through it, the import is not removed. However, as soon as you reference and use it inside getServerSideProps, Next.js automatically eliminates it from the imports.
Make sure to always comment out/remove unused imports (there are linting rules to help you do that).
Have you tried upgrading the next npm package to the latest version? (12.0.8 as of this writing). I had a similar issue with Next giving inconsistent errors between different API routes, all configured the same way but some raising the same TypeError you shared. Upgrading the package resolved the issue for me.

attempted relative import with no known parent package on Google AppEngine with Python3.7

Getting the following error:
"/srv/server.py", line 12, in from .routes.solver import route as solve ImportError: attempted relative import with no known parent package
Deploying the app to AppEngine Standard env, and my project looks like so:
---/
|_app.yaml
|_server.py
|_routes
|_solver.py
In server I do from .routes.solver import route as solve and get the above error in GCP, but not locally.
I tried https://stackoverflow.com/a/16985066/483616 and a few others. Tried with __init__.py at pretty much every level and every location. Then saw that it wasn't needed for python3, so removed. Pretty much unsure what to do now.
Not optimistic that this is the answer but just to throw it into the pot, have you seen Problem with Python relative paths when deploying to Google App Engine Flexible ?

How to import the googleapis npm package into meteor

I'm using the meteor framework, and trying to use google sheets to visualize some of my app's data. But for whatever reason, I can't seem to get the google api to load. I started with the command npm i googleapis and adding const {google} = require('googleapis') Which is to my knowledge correct. However, when I console.log(google) it spits out undefined.
I'm running Meteor 1.8.1, Node 6.12.0, and googleapi ^39.2.0
I would love to know what I'm doing wrong, most other people with this issue needed to update various other packages, so I've already run npm update To no avail, I've tried using import { google } from 'googleapis' Also to no avail, I saw somewhere that that would require transformations or something, but it still spits out undefined
I noticed that if I run require('googleapis') from my meteor shell, then it returns all the methods and whatnot that it's supposed to.
Ok, how I do it, to prevent adding another NPM to my Meteor projects ...
In my main.html I have this line:
<link rel="dns-prefetch" href="//maps.googleapis.com">
The next example shows adding google maps. I first make sure that, in a session, I load this library maximum once.
I call this code in multiple pages as I need the API. Since I use react, I do i in 'componentDidMount'.
if (!(window.google && window.google.maps)) {
const script = document.createElement('script')
script.src = 'https://maps.googleapis.com/maps/api/js?key=xxxxxxxxx&libraries=places'
script.defer = true
document.head.appendChild(script)
}
Removing my node_modules and running npm i did the trick

Webstorm Import url issues with Angular 2

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?

Resources