Migrating from require.context to import.meta.webpackContext - vue.js

I am trying to migrate my Vue PWA to ESM, replacing all require by import.
But replacing require.context by import.meta.webpackContext gives me the following warning at compile-time:
Critical dependency: Accessing import.meta directly is unsupported
(only property access is supported)
And then the following error at run-time:
Uncaught TypeError: {}.webpackContext is not a function
The way I use it is the following:
const icons = import.meta.webpackContext('../components/icon', false, /icon.*\.vue/);
I use webpack 5.75.0
I guess this is the same problem as this and this.

The error from webpack is misleading, the issue comes from the fact that import.meta.webpackContext has other arguments:
(
request: string,
options?: {
recursive?: boolean;
regExp?: RegExp;
include?: RegExp;
exclude?: RegExp;
preload?: boolean | number;
prefetch?: boolean | number;
chunkName?: string;
exports?: string | string[][];
mode?: 'sync' | 'eager' | 'weak' | 'lazy' | 'lazy-once';
}
) => webpack.Context;
So in my case I switched to the following to make it work:
const icons = import.meta.webpackContext('../components/icon', {recursive: false, regExp: /icon.*\.vue/});

Related

Where is the option to set maxParticipantDuration in JavaScript SDK?

I used the backend to obtain the Access Token, and connect (auto-create) to a room like this -
room = await Video.connect(accessToken, {
video: true,
audio: true,
name: "Room1",
});
I looked at ConnectOptions and I don't see anywhere that I can set the maxParticipantDuration for the room. Does anyone know where to set this? I know this can be set if the room is created using Rest API. Is this option not available if using the JavaScript SDK?
Rest API to Set maxParticipantDuration
No option in JavaScript SDK for the maximum Participant duration
From the manual
If you wish to configure the maximum Participant duration for you
Video Rooms, you can do so in two ways: via the Twilio REST API, or
via the Twilio Console.
BY API
// Download the helper library from https://www.twilio.com/docs/node/install
// Find your Account SID and Auth Token at twilio.com/console
// and set the environment variables. See http://twil.io/secure
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.video.v1.rooms
.create({
maxParticipantDuration: 86400,
uniqueName: 'My Video Room'
})
.then(room => console.log(room.sid));
By Twilio Console
So no option for maximum Participant duration in ConnectOptions here from JavaScript SDK
export interface ConnectOptions {
audio?: boolean | CreateLocalTrackOptions| CreateLocalAudioTrackOptions;
automaticSubscription?: boolean;
bandwidthProfile?: BandwidthProfileOptions;
dominantSpeaker?: boolean;
/**
* #deprecated use enableDscp
*/
dscpTagging?: boolean;
enableDscp?: boolean;
/**
* #deprecated use Video.Logger
*/
loggerName?: string;
eventListener?: EventListener;
iceServers?: Array<RTCIceServer>;
iceTransportPolicy?: RTCIceTransportPolicy;
insights?: boolean;
maxAudioBitrate?: number | null;
maxVideoBitrate?: number | null;
name?: string | null;
networkQuality?: boolean | NetworkQualityConfiguration;
notifyWarnings?: Array<NotifyWarning>;
region?: string;
preferredAudioCodecs?: Array<AudioCodec | AudioCodecSettings | OpusCodecSettings>;
preferredVideoCodecs?: Array<VideoCodec | VideoCodecSettings | VP8CodecSettings> | VideoEncodingMode;
/**
* #deprecated use Video.Logger.
*/
logLevel?: LogLevel | LogLevels;
tracks?: Array<LocalTrack | MediaStreamTrack>;
video?: boolean | CreateLocalTrackOptions;
}

Invalid array length

I'm trying to test this component on vue, but when I run the test I get the message down bellow:
RangeError: Invalid array length
96 | this.changeLogs.marketConfiguration.productTypes
97 | );
> 98 | return [
| ^
99 | ...new Set(
100 | productTypes.flatMap((productType) => productType.domains || [])
101 | )
I'm using Jest, with vue-test-utils.
And this is the function:
affectedDomains(): string {
const productTypes: ProductTypeConfiguration[] = Object.values(
this.changeLogs.marketConfiguration.productTypes
);
return [
...new Set(
productTypes.flatMap((productType) => productType.domains || [])
)
].join(', ');
}
Found a solution, in my case was to set the "downlevelIteration": true, on tsconfig.json.
Downleveling is TypeScript’s term for transpiling to an older version
of JavaScript. This flag is to enable support for a more accurate
implementation of how modern JavaScript iterates through new concepts
in older JavaScript runtimes.
More info

I am trying to get data over an OpenWeather API in Rust but I am facing some iusse regarding parsing I guess

extern crate openweather;
use openweather::LocationSpecifier;
static API_KEY: &str = "e85e0a3142231dab28a2611888e48f22";
fn main() {
let loc = LocationSpecifier::Coordinates {
lat: 24.87,
lon: 67.03,
};
let weather = openweather::get_current_weather(loc, API_KEY).unwrap();
print!(
"Right now in Minneapolis, MN it is {}K",
weather.main.humidity
);
}
error : thread 'main' panicked at 'called Result::unwrap() on an
Err value: ErrorReport { cod: 0, message: "Got unexpected response:
\"{\\"coord\\":{\\"lon\\":67.03,\\"lat\\":24.87},\\"weather\\":[{\\"id\\":803,\\"main\\":\\"Clouds\\",\\"description\\":\\"broken
clouds\\",\\"icon\\":\\"04n\\"}],\\"base\\":\\"stations\\",\\"main\\":{\\"temp\\":294.15,\\"pressure\\":1018,\\"humidity\\":60,\\"temp_min\\":294.15,\\"temp_max\\":294.15},\\"visibility\\":6000,\\"wind\\":{\\"speed\\":5.1,\\"deg\\":30},\\"clouds\\":{\\"all\\":70},\\"dt\\":1574012543,\\"sys\\":{\\"type\\":1,\\"id\\":7576,\\"country\\":\\"PK\\",\\"sunrise\\":1573955364,\\"sunset\\":1573994659},\\"timezone\\":18000,\\"id\\":1174872,\\"name\\":\\"Karachi\\",\\"cod\\":200}\""
}
The issue is a JSON parsing error due to the deserialized struct not matching OpenWeather's JSON, perhaps the API recently added this? With your example, the OpenWeatherCurrent struct is missing timezone.
But it looks like there is an open PR that will fix this, you can test it by doing the following:
Change your Cargo.toml dependency to openweather = { git = "https://github.com/caemor/openweather" }.
The PR author has also updated the get_current_weather signature so you'll need to change lines 2, 10 to the following:
use openweather::{LocationSpecifier, Settings};
let weather = openweather::get_current_weather(&loc, API_KEY, &Settings::default()).unwrap();

'TypeError: currentSubs[i] is not a function' when using ports in Elm 0.19

I am attempting to send data from Elm 0.19 to JavaScript using ports.
Edit: The problem seems to be related to running/building with elm-app
In Elm, I declare an outgoing port:
port modelToJs : Json.Encode.Value -> Cmd msg
which I use in the update function to produce a Cmd that sends a JSON encoded value to JavaScript.
In JS, I instantiate the Elm app:
const app = Elm.Main.init({
node: document.getElementById('root')
});
and register the data handler:
app.ports.modelToJs.subscribe(function dataHandler(data) {
console.log("got from Elm:" + data);
});
When modelToJs is called, the data is not sent and printed to the console. Instead, I get the following JavasScript runtime error (which Elm claims to avoid by design):
TypeError: currentSubs[i] is not a function
var value = _Json_unwrap(converter(cmdList.a));
2160 | for (var i = 0; i < currentSubs.length; i++)
2161 | {
> 2162 | currentSubs[i](value);
2163 | }
2164 | }
2165 | return init;
I have also provided a full proof of concept project on GitHub: https://github.com/mpgirro/elm0.19-ports-issue
The repo also contains an image of the error message (sry, I lack the reputation to post images)
The error appears to be in dataHandler.js. It currently contains this:
function dataHandler(data) {
console.log("got from Elm:" + data);
}
If you declare the function as export default the problem goes away:
export default function dataHandler(data) {
console.log("got from Elm:" + data);
}

Getting an invalid token on an interpolated string sent from python/jinga2 backend

I'm sending a variable called apiID from a tornado/jinja2 python file to my vuejs template like this:
class SmartAPIUIHandler(BaseHandler):
def get(self, yourApiID):
doc_file = "smartapi-ui.html"
dashboard_template = templateEnv.get_template(doc_file)
dashboard_output = dashboard_template.render(apiID = yourApiID )
self.write(dashboard_output)
then in vuejs I'm interpolating the variable with no problem except it gives me an error
it says: Uncaught SyntaxError: Invalid or unexpected token
I checked on the python handler file and apipID is a string, so I don't see the problem. I'm quite new to python so maybe the answer is more obvious to one of you. I appreciate the help!!
Because of dashboard_output = dashboard_template.render(apiID = yourApiID ), you must have, in your template, something around the code:
this.apiID = {{ apiID }};
Due to the value being not a number but a string, add the 's:
this.apiID = '{{ apiID }}';