import platform specific componet to a module in nativescript angular - nativescript

I have a component that I split into platform specific files
ex.component.ios.ts and ex.component.android.ts
my question is how to import it into the module because using just ex.component gives me an error
thanks.

i think it can be resolved using a ex.d.ts file that has
export const ex: any;

Related

Cannot import package in AWS lambda with Nodejs14.x ES module

I have a layer where the path of node_modules is nodejs/node14/node_modules.
Using that layer, and I try to import a package in a Lambda function, say 'aws-cloudfront-sign', like this:
import cfsign from 'aws-cloudfront-sign'
I got error message
Cannot find package 'aws-cloudfront-sign' imported from /var/task/signer.js\nDid you mean to import aws-cloudfront-sign/lib/cloudfrontUtil.js?
But if I import the package like this:
import cfsign from '/opt/nodejs/node14/node_modules/aws-cloudfront-sign/lib/cloudfrontUtil.js'
It succeeds.
Do you know why? How could I import the package correctly?
This appears to be a bug. It is occurring with layers and the SDK. There are are a number of similar open issues on Github:
Nodejs Lambda: Cannot find package 'aws-sdk'
Cannot find package when using ES Module and Lambda Layer
ES6 imports don't work in #aws-sdk/client-iotsitewise
As you have worked out, the only workaround at present seems to be the use of absolute paths. E.g.:
import { DynamoDB } from 'aws-sdk;'
fails, whereas
import AWS from '/var/runtime/node_modules/aws-sdk/lib/aws.js';
const { DynamoDB } = AWS;
will work.
I suggest you add your voice to an existing open issue to help ensure it gets attention.

How to properly import the MetricsServiceV2Client attribute from google.cloud.logging_v2 package?

I am trying to set up a locust based framework for ML load test and need to create custom metrics and logs for which the example that I am following is using 'MetricsServiceV2Client' in 'google.cloud.logging_v2' lib.
In the Vertex Workbench on GCP inspite being on v3.0 of the google-cloud-logging lib I am getting an issue of import
from google.cloud import logging_v2
from google.cloud.logging_v2 import MetricsServiceV2Client
error: cannot import name 'MetricsServiceV2Client' from 'google.cloud.logging_v2' (/opt/conda/lib/python3.7/site-packages/google/cloud/logging_v2/__init__.py)
Interestingly when I test the import in Google's cloud console I am able to import without any issue. What could be the issue?
Change it to the following:
from google.cloud.logging_v2.services.metrics_service_v2 import MetricsServiceV2Client
This will work.

Where to import React-Bootstrap components from?

I am using React-Bootstrap version 1.0.0-beta.10.
Whenever I want to use a component, for example Alert, I will get three import options from the IDE to choose from:
"react-bootstrap"
"react-bootstrap/Alert"
"react-bootstrap/es/Alert"
Which of them should I use and why?
Yes. We have multiple options to import a component.
When importing directly from react-bootstrap you need to import as,
import {Alert} from `react-bootstrap`;
Because Alert component is exported as named export.
If you expand the react-bootstrap folder from node_modules folder, you will see multiple folders and files.
The files directly available in react-bootstrap folder are based on ES5.
When I say based on ES5 means, the required package for this component are imported like this,
var _extends2 = _interopRequireDefault(require("#babel/runtime/helpers/extends"));
and you can import component as,
import Alert from `react-bootstrap/Alert`;
Because Alert component is exported as default export.
The files available in es folder are based on ES6.
When I say based on ES6 means, the required package for this component are imported like this,
import _extends from "#babel/runtime/helpers/esm/extends";
and you can import component as,
import Alert from `react-bootstrap/es/Alert`;
Because Alert component is exported as default export.
You must have to change your codebase.
react-bootstrap doesn't have a default export, so the default import syntax cannot be used in this case.
You can do the following though:
import * as ReactBootstrap from 'react-bootstrap';
And then, you can use the Alert component.

es6 module import of d3 4.x fails

TL;DR: The documented way to import d3 into es6 modules fails. What is the correct way to do this? My guess is the documentation assumes I use a workflow that resolves these problems
Details:
The readme for d3 4.x says:
D3 is written using ES2015 modules. Create a custom bundle using Rollup, Webpack, or your preferred bundler. To import D3 into an ES2015 application, either import specific symbols from specific D3 modules:
import {scaleLinear} from "d3-scale";
Or import everything into a namespace (here, d3):
import * as d3 from "d3";
Yet when I yarn add d3 and use a es6 script tag, this fails to work:
<html>
<head>
<title>D3</title>
</head>
<body>
<script type="module">
import * as d3 from "./node_modules/d3"
</script>
</body>
</html>
Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
Replacing the import with:
import * as d3 from "./node_modules/d3/index.js"
..gives this error:
Uncaught TypeError: Failed to resolve module specifier 'd3-array'
#jimmont is correct: importing the module form of d3 packages does not work without local building due to the "bare" imports. These can be resolved by the CDN's D3 uses, in particular unpkg.com. Here's the story.
It turns out d3 uses package.json to allow it to export two formats from a single source, npm itself. To do so, it uses the module: field.
The easiest way to access either all of d3, or a submodule/repo (there are 30 of them!) unpkg is ideal:
A dashboard to the repo: https://unpkg.com/d3/
The current umd/iife: https://unpkg.com/d3
The current collection of all modules: https://unpkg.com/d3?module
To import all of d3:
import * as d3 from 'https://unpkg.com/d3?module'
To import sub-modules:
import * as selection from 'https://unpkg.com/d3-selection?module'
es6 and es2015 modules will not work with d3 because d3 has chosen to use rollup instead. You are seeing this error because the module cannot be resolved as specified in the file "./node_modules/d3/index.js" which has lines like export {default as ascending} from "./src/ascending"; which are missing the real file name which ends with '.js'. So in other words all these entries are mis-configured to not support native modules in browsers or Nodejs.
you can either use rollup or make all the text substitutions yourself using a script or manually. I use a perl one-liner because I dislike rollup and the extra dependencies were breaking between node 8 and node 10. it is unbelievably strange that this is necessary but I also haven't been supporting a kitchen sink of module loaders.
import * as d3 from "./node_modules/d3-something/index.js"
which has content like export {default as something} from './src/thing'. because these files do not use the natively supported syntax with a full relative path (it's missing the actual file extension), it won't work without rollup or whatever making these corrections. multiple popular projects have made this same decision to require extra modules to work properly and forego native support.
see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import

Swift - Import my swift class

This question is asked several times, but I can't find the right solution for my problem. I'm trying to import my Player.swift class in my MainScene.swift (I've used Cocos2D - SpriteBuilder to setup the project; Now using Xcode).
This is my folder structure:
I've tried to use import Player; and import Player.swift;, but when I tried I got this error: No such module 'Player.swift'
How do I import it correctly?
Thanks!
By the way, I'm a beginner in Swift, so don't expect that I know all of the terms
You don't need to explicitly import files in Swift as they are globally available through the project. If you want to access the methods or properties of Player class, you can directly make object of Player class in MainScene.Swift file and can access to it.
e.g var objPlayer = Player()
There is no need to import swift classes to use in other swift classes.
They are available to use automatically.
In Swift you can only import module, e.g. any framework like UIKit, MapKit as below. You cannot import swift classes.
import UIKit
import MapKit
Just make sure its selected to use in target in which your are trying to use.
Check below images for more idea.
In this image my HomeViewController.swift is selected to use in AutolayoutDemo module.
In below image I have unchecked AutolayoutDemo module for the class DetailsViewController.swift.
So now onwards when I will try to use the DetailsViewController compiler will give me error as below image in HomeViewController.
When it comes to Swift imports, there are two cases:
1) The type to import is in the module
In this case, no import statement is needed. As long as the type is not private or fileprivate, you can directly access it.
2) The type to import is outside of the module
You can import an entire module using:
import ModuleName
If you only want to import a specific type or function from the module, you can do this using the following format:
import kindOfThing ModuleName.Type
where kindOfThing is class/struct/func/etc...
A much deeper exploration of this can be found on NSHipster here.
Check if the class is added to your iOS target in right Pane or not .

Resources