VSCode automatically breaking paths in Node.js app - node.js

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.

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 ?

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.

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