in pre-es6:
var stream = require("./models/stream");
var stream = require("./routes/stream");
It works fine.
In es6:
import stream from './models/stream';
import stream from './routes/stream';
Error:
TypeError: /var/www/.../es6/app.js: Duplicate declaration "stream"
> 31 | import stream from './routes/stream';
Any ideas how can I import it properly?
Use different module names
import stream from './models/stream';
import streamroutes from './routes/stream';
You are re-declaring the stream variable and never use it, so you can just import first file without assignment:
import './models/stream';
import stream from './routes/stream';
Related
I get this error when i try to send a txt file to a discord webhook. (python3)
import os
import subprocess
import requests
import discord
import dhooks
from dhooks import Webhook, Embed
hook = Webhook("hook")
Discord_txt = open("data.txt", "r+")
hook.send(file=Discord_txt)
According to the docs, you should be using the File class from dhooks:
from dhooks import Webhook, File
hook = Webhook("https://discord.com/api/webhooks/...")
Discord_txt = File("data.txt")
hook.send(file=Discord_txt)
I am trying out the new Node 12 module import syntax and cannot get static functions from rxjs to work.
I've tried both Typescript-style import syntax and ideas from the new module documentation.
// SyntaxError: The requested module 'rxjs' does not provide an export named 'interval'
import { interval } from 'rxjs';
const x = interval(1000)
// TypeError: interval is not a function
import interval from 'rxjs';
const x = interval(1000)
// TypeError: interval is not a function
import interval from 'rxjs/observable/interval.js';
const x = interval(1000)
Any idea what the correct way is to import static functions?
UPDATE: One way that works:
import Observable from 'rxjs';
const x = Observable.interval(1000).subscribe(() =>
console.log('' + new Date().toISOString())
)
I'm importing object to a .ts file but it is undefined, when I do the same with require keyword , then it is working. But I'd like to understand whats happening
const jwt = require('jsonwebtoken'); // working
import {jwt2} from 'jsonwebtoken'; // not working
The first example is importing the entire module, while the second one is trying to import a member of the module named jwt2, but there is no such member. To import the entire module using import, try:
import * as jwt2 from 'jsonwebtoken';
import org.apache.spark.SparkConf
import org.apache.spark.storage.StorageLevel
import org.apache.spark.streaming.Milliseconds
import org.apache.spark.streaming.StreamingContext
import org.apache.spark.streaming.dstream.DStream.toPairDStreamFunctions
import com.amazonaws.auth.AWSCredentials
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
import com.amazonaws.auth.SystemPropertiesCredentialsProvider
import com.amazonaws.services.kinesis.AmazonKinesisClient
import com.amazonaws.services.kinesis.clientlibrary.lib.worker.InitialPositionInStream
import org.apache.spark.streaming.kinesis.KinesisInputDStream
import org.apache.spark.streaming.kinesis.KinesisInitialPositions.Latest
import org.apache.spark.streaming.kinesis.KinesisInitialPositions.TrimHorizon
import java.util.Date
val tStream = KinesisInputDStream.builder
.streamingContext(ssc)
.streamName(streamName)
.endpointUrl(endpointUrl)
.regionName(regionName)
.initialPosition(new TrimHorizon())
.checkpointAppName(appName)
.checkpointInterval(kinesisCheckpointInterval)
.storageLevel(StorageLevel.MEMORY_AND_DISK_2)
.build()
tStream.foreachRDD(rdd => if (rdd.count() > 0) rdd.saveAsTextFile("/user/hdfs/test/") else println("No record to read"))
Here, even though I see data coming into the stream, my above spark job isn't getting any records. I am sure that I am connecting to right stream with all credentials.
Please help me out.
There seem to be different forms of import in Typescript for CommonJS (node) style modules:
If I have a pure javascript module (without an ambient definition), this seems to be fine:
var pureJavascript = require("pure-javascript");
But using import fails on pure javascript modules:
import pureJavascript = require("pure-javascript");
Unless I have an ambient definition for the javascript module. Then I can use
import * as jsWithAmbient from "js-with-ambient";
Provided the module exports foo and bar, I can also use
import {foo} from "./my-module";
import {foo, bar} from "./my-module";
import {foo as x, bar as y} from "./my-module";
Sometimes this seems to be the way of importing:
import abc from "./my-module";
which seems to be the same as
import {default as abc} form "./my-module";
When to use which of the import styles?