JSPM Map For Dependencies Not Resovling Path Correctly - systemjs

I'm having significant frustration with JSPM, this is just the latest problem out of many.
I've installed angularfire2 via JSPM via - sudo jspm install npm:angularfire2 (Yes, SUDO. Doesn't work without SUDO!!) which should have installed #angular dependencies. The generated package json looks like this-
"jspm": {
"dependencies": {
"angularfire2": "npm:angularfire2#^2.0.0-beta.2"
},
"devDependencies": {
"typescript": "npm:typescript#^1.8.10"
}
}
And the generated config looks like this-
System.config({
baseURL: "/",
defaultJSExtensions: true,
transpiler: "typescript",
typescriptOptions: {
"emitDecoratorMetadata": true
},
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
},
packages: {
"app": {
"main": "./app.ts",
"defaultExtension": "ts"
}
},
map: {
"angularfire2": "npm:angularfire2#2.0.0-beta.2",
"typescript": "npm:typescript#1.8.10",
...
"npm:angularfire2#2.0.0-beta.2": {
"#angular/common": "npm:#angular/common#2.0.0-rc.2",
"#angular/compiler": "npm:#angular/compiler#2.0.0-rc.2",
"#angular/core": "npm:#angular/core#2.0.0-rc.2",
"#angular/platform-browser": "npm:#angular/platform-browser#2.0.0-rc.2",
"#angular/platform-browser-dynamic": "npm:#angular/platform-browser-dynamic#2.0.0-rc.2",
"firebase": "npm:firebase#3.0.5",
"rxjs": "npm:rxjs#5.0.0-beta.6"
}
...
}
});
So when I refresh the page of the application I see it imports angularfire2.js correctly, then tries to import #angular/platform-browser-dynamic.js. But the address it is trying to import at is- http://localhost:8000/#angular/platform-browser-dynamic.js which is the wrong path! I imagine it's because the first line of my app.ts (and the starting point of the application) has this line- import { bootstrap } from '#angular/platform-browser-dynamic';. But what WHY doesn't JSPM map this correctly? Do I need to install these packages separately? If so- WHY is there such a thing as package dependencies?
Expected: When resolving this import, the /jspm_packages/npm/** address should be resolved.
Got: SystemJS attempts to load package from the web root /.

You have to manually add the following in the map.
"#angular/common": "npm:#angular/common#2.0.0-rc.2",
"#angular/compiler": "npm:#angular/compiler#2.0.0-rc.2",
"#angular/core": "npm:#angular/core#2.0.0-rc.2",
"#angular/platform-browser": "npm:#angular/platform-browser#2.0.0-rc.2",
"#angular/platform-browser-dynamic": "npm:#angular/platform-browser-dynamic#2.0.0-rc.2",
Not sure if that's the real solution but it works. The future is here.

Related

Ionic StorageModule no data after update

for the update of an ionic app from 5.3.4 to 6.1.13, also the ionic storage package changed from #ionic/storage (version 2) to #ionic/storage-angular (version 3). The whole app works fine, however I am unable to get already saved data with the new storage-module:
Old App (Ionic 5)
package.json:
"#angular/core": "~9.1.6",
"#ionic/angular": "^5.3.4",
"#ionic/storage": "^2.3.1",
app.module:
import { IonicStorageModule } from '#ionic/storage';
#NgModule({
...
imports: [
IonicModule.forRoot(),
IonicStorageModule.forRoot({
name: '__mydb',
driverOrder: ['sqlite', 'websql', 'indexeddb'],
}),
...
New App (Ionic 6, new angular-storage module)
package.json:
"#angular/core": "^14.0.5",
"#ionic/angular": "^6.1.13",
"#ionic/storage-angular": "^3.0.6",
app.module:
import { Drivers } from '#ionic/storage';
import { IonicStorageModule } from '#ionic/storage-angular';
#NgModule({
...
imports: [
IonicStorageModule.forRoot({
name: '__mydb',
driverOrder: [CordovaSQLiteDriver._driver, Drivers.IndexedDB, Drivers.LocalStorage],
}),
...
I even tried to downgrade to the old storage package (same version as in old app), still I am unable to retrieve the already saved data:
New App (Ionic 6, old storage module)
package.json:
"#angular/core": "^14.0.5",
"#ionic/angular": "^6.1.13",
"#ionic/storage": "2.3.1",
app.module:
import { IonicStorageModule } from '#ionic/storage';
#NgModule({
...
imports: [
IonicStorageModule.forRoot({
name: '__mydb',
driverOrder: ['sqlite', 'websql', 'indexeddb'],
}),
...
I would appreciate any insights / tips, the database name did not change and the data is still there, because if I install the old version again all data is retrieved successfully. But If I try to get the data (same key) with the updated ionic app, regardless of old or new storage package, I can't retrieve the data
Saving / retrieving new data with the new storage module works fine as well!
Testes with both IOS and Android

ERR_REQUIRE_ESM require of of ES Module not supported how can I fix this? on file-type package

I've a outdated app that uses very older few packages those doesn't support ES Module as an example file-type package. So if you setup babel and node HTTP server with and then install file-type package then start building and running will throw error message like below:
Error [ERR_REQUIRE_ESM]: require() of ES Module E:\test\testbabel\node_modules\file-
type\index.js from E:\test\testbabel\dist\index.js not supported.
Instead change the require of E:\test\testbabel\node_modules\file-type\index.js in
E:\test\testbabel\dist\index.js to a dynamic import() which is available in all CommonJS
modules.
at Object.<anonymous> (E:\test\testbabel\dist\index.js:10:17) {
code: 'ERR_REQUIRE_ESM'
}
I tried this on a fresh project though my old project has an outdated config or so, It still throwing this error
Here are my index.js codes
import http from 'http';
import { fileTypeFromFile } from 'file-type';
const server = http.createServer((req, res) => {
res.end('Hello from the server');
}).listen(4001);
console.log('Server is up and running');
export default server;
file package.json.
{
"name": "testbabel",
"version": "1.0.0",
"description": "test babel with http or express",
"main": "index.js",
"scripts": {
"build": "babel index.js -d dist",
"start": "npm run build && node dist/index.js"
},
"author": "",
"license": "ISC",
"devDependencies": {
"#babel/cli": "^7.17.10",
"#babel/core": "^7.18.2",
"#babel/plugin-transform-modules-commonjs": "^7.18.2",
"#babel/preset-env": "^7.18.2"
},
"dependencies": {
"file-type": "^17.1.1"
}
}
I just tried to import the package and got the errors above.
attempt:
I thought a converter might help so used #babel/plugin-transform-modules-commonjs but still didn't help, and seems no effect on including that package
I'm not sure but added some tweaks on package.json like "type": "module" "type": "commonjs" didn't help at all.
what is the easiest solution for this issue and how do we fix it?
Note: I saw people were going back to the supported package instead of new one which doesn't make sense to me as a solution.
Option1(babel with mocha): Rename "index.js" to "index.mjs" and modify file-type's pacakage.json ("index.js" to "index.mjs"), then leave Babel to transpile for you.
// babel-register.js
const babel_register = require("#babel/register").default;
babel_register({
ignore: [
// Only work on Project-wide configuration
// overrides ignore can transpile packages(modules) from node_modules (https://babeljs.io/docs/en/babel-register/#ignores-node_modules-by-default)
],
});
Use babel.config instead of .babelrc
//.mocharc.js
require("./babel-register");
module.exports = {
// https://github.com/mochajs/mocha/blob/v8.4.0/example/config/.mocharc.js
ui: "bdd",
timeout: 5000,
recursive: true,
};
Option2(babel only): Using dynamic import expression
async function doSomething() {
const {fileTypeFromStream} = await import("file-type");
}
and
["#babel/preset-env", {
exclude: ["proposal-dynamic-import"]
}]
Avoiding Babel tanspile dynamic import expression

social share button in angular 10 ngx-sharebuttons

I am implementing the ngx-sharebuttons for social share button like facebook, whatsapp.
this is what I tried
installed package
npm i cdk
npm i ngx-sharebuttons
npm i #fortawesome/fontawesome-svg-core #fortawesome/angular-fontawesome #fortawesome/free-solid-svg-icons #fortawesome/free-brands-svg-icons
import { ShareButtonsModule } from 'ngx-sharebuttons/buttons';
import { ShareIconsModule } from 'ngx-sharebuttons/icons';
ShareButtonsModule.withConfig({
debug: true
}),
ShareIconsModule
<share-buttons [theme]="'material-dark'"
[include]="['facebook','twitter','linkedin','pinterest','reddit','mix','vk','telegram','messenger','whatsapp','xing','line','sms','email','copy']"
[show]="9"
[size]="1"
[url]="'https://www.eduforbetterment.com/generate-qr-code-in-angular/'"
[image] ="'https://www.eduforbetterment.com/wp-content/uploads/2020/08/qrcode.jpg'"
[autoSetMeta]="false"
></share-buttons>
everything is working but I am not able to see the social icons for share like facebook, twitter, whatsapp and so on.
I followed this link
As you can see in the image share button is creating but icons are not creating.
below is my package.json file
"#angular-devkit/core": "10.0.1",
"#angular/animations": "^10.0.2",
"#angular/cdk": "^11.0.0",
"#angular/cli": "^10.0.1",
"#angular/common": "10.0.2",
"#angular/compiler": "10.0.2",
"#angular/core": "10.0.2",
"#angular/flex-layout": "^9.0.0-beta.29",
"#angular/forms": "10.0.2",
"#angular/localize": "^10.0.2",
"#angular/material": "^8.2.3",
"#angular/platform-browser": "10.0.2",
"#angular/platform-browser-dynamic": "10.0.2",
"#angular/router": "10.0.2",
"#fortawesome/angular-fontawesome": "^0.8.0",
"#fortawesome/fontawesome-svg-core": "^1.2.32",
"#fortawesome/free-brands-svg-icons": "^5.15.1",
"#fortawesome/free-solid-svg-icons": "^5.15.1",
"#ng-bootstrap/ng-bootstrap": "^7.0.0",
"bootstrap": "^4.5.2",
"chartist": "^0.11.4",
"core-js": "^2.6.11",
"hammerjs": "^2.0.8",
"ng-chartist": "4.1.0",
"ngx-sharebuttons": "^8.0.4",
"ngx-spinner": "^10.0.1",
"node-sass": "^4.13.1",
"rxjs": "^6.6.0",
"rxjs-compat": "^6.6.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.3"
Please help me where I am doing wrong.
I used fontawesome icons instead (you import what you need)
import { faFacebookF, faTwitter } from '#fortawesome/free-brands-svg-icons';
import { FaIconLibrary } from '#fortawesome/angular-fontawesome';
constructor(
iconLibrary: FaIconLibrary,
) {
iconLibrary.addIcons(faTwitter, faFacebookF);
}
Try this one
[shareButton] is a directive that converts its host element to a share button.
https://ngx-sharebuttons.netlify.app/#/share-button-directive

How to detect the orientation change event in device in ionic

I want to detect the device orientation change event.
I need to change the image while orientation change in the device.
I tried some of the examples but it is not working at all.
I also tried the screen-orientation plugin but it also not working.
Plugin which I used
ionic cordova plugin add cordova-plugin-screen-orientation
npm install #ionic-native/screen-orientation
These are in my package.json.
"#ionic-native/app-preferences": "^4.18.0",
"#ionic-native/call-number": "^4.18.0",
"#ionic-native/core": "~4.17.0",
"#ionic-native/file": "^5.0.0",
"ionic-angular": "3.9.2"
Have you tried that with the screen-orientation plugin, that you have:
import { ScreenOrientation } from '#ionic-native/screen-orientation/ngx';
constructor(private screenOrientation: ScreenOrientation) { }
...
this.screenOrientation.onChange().subscribe(
() => {
console.log("Orientation changed to " + this.screenOrientation.type);
}
);

regeneratorRuntime is not defined (how keep babel from including that polyfill?)

I continue to get:
App.jsx:11 Uncaught ReferenceError: regeneratorRuntime is not defined
on any line that does an async. I don't what that polyfill, but I am having a hard time getting rid of it:
app.jsx:11)
const fetcher = (async () => {
"#babel/cli": "^7.4.4",
"#babel/core": "^7.4.4",
"#babel/preset-env": "^7.4.4",
"#babel/preset-react": "^7.0.0",
"#types/react": "^16.8.17",
"babel-preset-env": "^1.7.0"
here is the .babelrc
{
"presets": [
[
"#babel/preset-env",
{
"targets": {
"chrome": ">70",
},
"exclude": ["transform-regenerator"]
},
"#babel/preset-react"
]
]
}
If you want to use async, await with (ES6 or ES Next) then you must need to install #babel/polyfill but you don't need to write anything in babelrc file. Just install
npm install --save #babel/polyfill
From the documentation:
Because this is a polyfill (which will run before your source code),
we need it to be a dependency, not a devDependency
And finally you need to import #bable/polyfill in your mainJS (App.js) file like:
import "#babel/polyfill";
This appears to be a bug in the parcel js bundler.
https://github.com/babel/babel/issues/9971