Importing draw2d in react causes jquery reference error - node.js

As soon as I add import draw2d from "draw2d" to my imports I get ReferenceError: jQuery is not defined.
I tried installing and adding jquery but still get same error...
import React, {Component} from "react";
import jQuery from "jquery";
import draw2d from "draw2d";

Create a file with any name, e.g. import-jquery.js
import-jquery.js
import jquery from "jquery";
window.$ = window.jQuery = jquery;
App.js
import "import-jquery";
import "jquery-ui-bundle"; // you also need this
import "jquery-ui-bundle/jquery-ui.css";
import draw2d from "draw2d";
EDIT:
And don't forget to...
npm install jquery
npm install jquery-ui-bundle

Related

My Vue NPM imports can only find the modules if they are inside the src folder and not project root

In my app root, I have /node_modules/ and /src/
I have ran npm install and installed packages using npm install axios --save etc for all my dependencies
I do see that they are being added to the node_modules directory however my vue project does not compile with the following error:
Failed to compile.
./src/main.js
Module not found: Error: Can't resolve 'axios' in '/app/src'
If I manually create a node_modules folder inside of my /src/ directory, and place axios, and my other dependencies it works.. but from what I've read I should not be handling my node modules this way. It seems I need to have my dependencies point to a different path?
What's weird is my import Vue from 'vue' and App from './App.vue' work fine, it's basically everything afterwards that fails to compile..
My main.js :
import Vue from 'vue'
import App from './App.vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import firebase from 'firebase'
import "firebase/auth";
import "firebase/analytics";
import "firebase/firestore";
import moment from 'moment'
Vue.use(VueAxios, axios)
Vue.config.productionTip = false
new Vue({
render: h => h(App),
firebase: firebase,
}).$mount('#app')
I have also tried removing all node modules, clearing NPM cache and reinstalling NPM dependencies to no avail.
instead of use the use function to add your axios instance globally can you please try to add it like this:
import Vue from 'vue'
import App from './App.vue'
import axios from 'axios'
import VueAxios from 'vue-axios'
import firebase from 'firebase'
import "firebase/auth";
import "firebase/analytics";
import "firebase/firestore";
import moment from 'moment'
Vue.config.productionTip = false
Vue.prototype.$axios = Axios; //<---- like that
new Vue({
render: h => h(App),
firebase: firebase,
}).$mount('#app')
after that try to compile again. you are then able to call your axios instance on every component with this.$axios
this error accrues when compiler cant find module or file you want to import within your node modules file
when module cant be found compiler goes to current directory to find that and if it cant find it through this error

Import node package vue.js loader webpack

I am using the basic vue loader setup with webpack(https://vue-loader.vuejs.org/en/start/setup.html).
In my main.js I import the necessary:
import Vue from 'vue'
import App from './App.vue'
import firebase from 'firebase'
import docx2html from 'docx2html'
Both firebase and docx2html are in the node_modules folder under src and specified in the dependencies folder. For some reason firebase is imported, but docx2html can not be found. It returns the error:
Module not found: Error: Can't resolve 'docx2html' in
'C:\path\to\src'.
How should I import docx2html, and why doesn't it work this way?

Importing DocumentReference in Es6

Classes like DocumentReference, CollectionReference, etc., don't seem to be exported. Is there a way to import these classes?
Install firebase if it's not in your package.json:
npm install --save firebase
In the .ts file just import whatever you need:
import * as firebase from 'firebase/app'
import DocumentReference = firebase.firestore.DocumentReference
Use DocumentReference:
posts.forEach((doc: DocumentReference) => {
doc.ref.delete()
})
using typescript, this works:
import * as firebase from "firebase"
then do
firebase.firestore().DocumentReference

Import unqualified name in Node.js

In Python I can import the names in my module as qualified
import myModule
or unqualified
from myModule import *
In Node.js, I can import as qualified
var myModule = require('myModule')
Is there a way to import names unqualified?
You can do that in ES6: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import
ES6 imports are not supported in node.js at this point though. You could get it by writing ES6 code and transpiling it with babel, for example https://babeljs.io/

Android studio unable to import WearableExtender NotificationManagerCompat and RemoteInput

I have a project class with the following imports:
import android.app.Activity;
import android.app.Fragment;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.RemoteInput;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Action;
import android.support.v4.app.NotificationCompat.WearableExtender;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
import android.text.Html;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
In android studio the following three bring up a 'cannot resolve symbol' error:
import android.support.v4.app.NotificationCompat.WearableExtender;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput;
Wierdly, the import for NotificationCompat and NotificationCompat.Action in android.support.v4.app are successful
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Action;
I have tried to use the same imports on eclipse (pointing to the same SDK as android studio) and the same worked and ran without any errors.
I've also tried Minto's solution of invalidating caches/restarting android studio ...my SDK is up to date as at the time of posting. Thanks for any help in advance
Make sure that you put the following entry into your application's build.gradle file to provide the necessary dependencies:
dependencies {
compile 'com.android.support:support-v4:20.0+'
}
The version number is important, if you specify an older version it will be missing the new Notification code for wearables.
Google has moved some of these tools into the standard libraries. For example, WearableExtender is in Android.app.Notification now. Try ditching the import statements giving you problems, and let Android Studio suggest what to import. Lots of Google's guides have outdated or otherwise incorrect code right now, as they have recently rolled out Google Play Services 5 and other official releases of preview products.

Resources