Ionic 4 Camera/ActionSheet Object(...) is not a function - object

I'm trying to use Camera Plugin in Ionic 4, and when the serve is started without errors, in the browser console appears this error:
I remove the folder node_modules and reinstall it, but can't fix this.
npm install
With ActionSheet I have the same error.
Dependencies in Package:
"dependencies": {
"#angular/common": "~6.1.1",
"#angular/core": "^6.1.2",
"#angular/forms": "~6.1.1",
"#angular/http": "~6.1.1",
"#angular/platform-browser": "^6.1.2",
"#angular/platform-browser-dynamic": "~6.1.1",
"#angular/router": "~6.1.1",
"#ionic-native/action-sheet": "^4.11.0",
"#ionic-native/camera": "^4.11.0",
"#ionic-native/core": "^5.0.0-beta.14",
"#ionic-native/file-transfer": "^4.11.0",
"#ionic-native/network": "^4.11.0",
"#ionic-native/splash-screen": "5.0.0-beta.14",
"#ionic-native/status-bar": "5.0.0-beta.14",
"#ionic/angular": "^4.0.0-beta.2",
"#ionic/lab": "^1.0.6",
"#ionic/ng-toolkit": "^1.0.6",
"#ionic/schematics-angular": "^1.0.0",
"cordova-android": "^7.1.1",
"cordova-android-support-gradle-release": "^1.4.4",
"cordova-ios": "4.5.5",
"cordova-plugin-actionsheet": "^2.3.3",
"cordova-plugin-camera": "^4.0.3",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-file": "^6.0.1",
"cordova-plugin-file-transfer": "^1.7.1",
"cordova-plugin-ionic-keyboard": "^2.1.2",
"cordova-plugin-ionic-webview": "^2.0.2",
"cordova-plugin-network-information": "^2.0.1",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-whitelist": "^1.3.3",
"core-js": "^2.5.3",
"promise-polyfill": "^8.0.0",
"rxjs": "^6.2.2",
"rxjs-compat": "^6.2.2",
"zone.js": "^0.8.26"
},
Thanks
EDIT: When I tried to compile it! (using ActionSheet)
--verbose:
ionic:cli-framework:utils:process onBeforeExit handler: process.exit received +0ms
ionic:cli-framework:utils:process onBeforeExit handler: running 1 queued functions +6ms
ionic:cli-framework:utils:process error while killing process tree for 8104: { Error: Command failed: taskkill /pid 8104 /T /F ERROR: no se encontr� el proceso "8104". at ChildProcess.exithandler (child_process.js:275:12) at emitTwo (events.js:126:13) at ChildProcess.emit (events.js:214:7) at maybeClose (internal/child_process.js:925:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) killed: false, code: 128, signal: null, cmd: 'taskkill /pid 8104 /T /F' } +60ms
net.js:714
throw new TypeError(
^
This error appears only if some TS file has the import. It does not matter if it is used.
import { ActionSheet, ActionSheetOptions } from '#ionic-native/action-sheet';

I have solved it!
I need to install #5.0.0-beta.17 packages.
npm i -s #ionic-native/camera#5.0.0-beta.17
npm i -s #ionic-native/action-sheet#5.0.0-beta.17
Then, I can use it with:
import { Camera, CameraOptions } from '#ionic-native/camera/ngx';
import { ActionSheet, ActionSheetOptions } from '#ionic-native/action-sheet/ngx';

Make sure you have installed Camera plugin and node modules correctly
Step 1: Delete current node modules and reinstall using
npm install
Step 2: Rebuild the platform (Delete old platform) and install plugin
$ ionic cordova plugin add cordova-plugin-camera
$ npm install --save #ionic-native/camera
In your TS file
import { Component } from '#angular/core';
import { IonicPage, NavController,ActionSheetController } from 'ionic-angular';
import { Camera, CameraOptions } from '#ionic-native/camera';
import { Storage } from '#ionic/storage';
#IonicPage()
#Component({
selector: 'page-field-observation',
templateUrl: 'field-observation.html',
})
export class FieldObservationPage {
CapturedImageURL:any;
constructor(
public navCtrl: NavController,
private camera: Camera,
public actionSheetCtrl: ActionSheetController,
public storage:Storage
){
}
ionViewDidLoad() {
}
captureImage() {
const CamOptions: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
sourceType: this.camera.PictureSourceType.CAMERA,
targetWidth:1024,
targetHeight:720
}
this.camera.getPicture(CamOptions).then((imageData) => {
console.log(imageData);
this.CapturedImageURL = imageData;
});
}
captureImageGallery(){
const options: CameraOptions = {
quality: 100,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.JPEG,
mediaType: this.camera.MediaType.PICTURE,
sourceType:0,
saveToPhotoAlbum:true,
targetWidth:1024,
targetHeight:720,
allowEdit:true
}
this.camera.getPicture(options).then((imageData) => {
this.CapturedImageURL = imageData;
});
}
CameraActionSheet() {
let actionSheet = this.actionSheetCtrl.create({
title: 'Choose an image from',
enableBackdropDismiss:true,
buttons: [
{
text: 'Camera',
icon: 'camera',
handler: () => {
this.captureImage();
}
},
{
text: 'Library',
icon: 'image',
handler: () => {
this.captureImageGallery();
}
},
{
text: 'Cancel',
role: 'cancel',
icon:'close-circle',
handler: () => {
console.log('Cancel clicked');
}
}
]
});
actionSheet.present();
}
}

Related

Unexpected token '<' jest and testing-library/react-native with typescript test file

I'm getting the following error when running the following test file:
// TestComp.test.tsx
import React from "react";
import { TextInput, View } from "react-native";
import { render, fireEvent } from "#testing-library/react-native";
const TestComp = () => {
return (
<View>
<TextInput testID="test-input" onChangeText={(txt) => console.log(txt)}></TextInput>
</View>
);
};
describe("Testcomp", () => {
afterEach(() => {
jest.clearAllMocks();
});
test("test me", async () => {
const { getByTestId } = render(<TestComp />);
const testInput = getByTestId("test-input");
fireEvent.changeText(testInput, "hello");
});
});
Error when running yarn jest:
Details:
/mnt/ubuntu/home/richardwu/code/topspin/src/components/TestComp.test.tsx:46
return (<react_native_1.View>
^
SyntaxError: Unexpected token '<'
at compileFunction (node:vm:355:18)
The error disappears if I change the file to jsx. The issue is the components I will be importing will be in tsx files, so ideally I want jest to be able to run with tsx files.
I've followed the instructions for setting up typescript with jest, where I have the following config files:
// jest.config.js
module.exports = {
preset: "react-native",
transform: {
"^.+\\.tsx?$": "ts-jest",
"^.+\\.jsx?$": "babel-jest",
},
transformIgnorePatterns: ["node_modules/?!(react-icons)"],
setupFilesAfterEnv: ["<rootDir>/src/setupTests.ts"],
};
// babel.config.js
module.exports = function (api) {
api.cache(true);
return {
presets: ["babel-preset-expo", "#babel/preset-typescript"],
};
};
// package.json
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"test": "jest"
},
"dependencies": {
"#apollo/client": "^3.2.5",
"#expo-google-fonts/inter": "^0.1.0",
"#react-native-community/masked-view": "0.1.10",
"#types/jest": "^26.0.19",
"#types/react-router-native": "^5.1.0",
"expo": "~39.0.2",
"expo-auth-session": "~2.0.0",
"expo-constants": "~9.2.0",
"expo-facebook": "~9.0.0",
"expo-font": "~8.3.0",
"expo-status-bar": "~1.0.2",
"firebase": "^8.0.0",
"graphql": "^15.4.0",
"native-base": "^2.13.14",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-hook-form": "^6.11.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-39.0.4.tar.gz",
"react-native-deck-swiper": "^2.0.5",
"react-native-elements": "^3.0.0-alpha.1",
"react-native-expo-viewport-units": "^0.0.8",
"react-native-fbsdk": "^2.0.0",
"react-native-gesture-handler": "~1.7.0",
"react-native-reanimated": "~1.13.0",
"react-native-safe-area-context": "3.1.4",
"react-native-screens": "~2.10.1",
"react-native-swipe-cards": "^0.1.1",
"react-native-web": "~0.13.12",
"react-router-native": "^5.2.0",
"react-tinder-card": "^1.3.1",
"ts-jest": "^26.4.4"
},
"devDependencies": {
"#babel/core": "^7.12.10",
"#babel/preset-env": "^7.12.11",
"#babel/preset-typescript": "^7.12.7",
"#testing-library/jest-dom": "^5.11.5",
"#testing-library/react-native": "^7.1.0",
"#types/react": "^16.9.56",
"#types/react-dom": "^16.9.9",
"#types/react-native": "^0.63.34",
"#types/react-test-renderer": "^17.0.0",
"babel-jest": "^26.6.3",
"eslint": "^7.13.0",
"eslint-plugin-jest": "^24.1.3",
"jest-expo": "^39.0.0",
"react-test-renderer": "^17.0.1",
"typescript": "^4.0.5"
},
"private": true,
"jest": {
"preset": "jest-expo",
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?react-native|react-clone-referenced-element|#react-native-community|expo(nent)?|#expo(nent)?/.*|react-navigation|#react-navigation/.*|#unimodules/.*|unimodules|sentry-expo|native-base|#sentry/.*)"
]
}
}
Since you are already using Babel and #babel/preset-typescript, you can update your Jest config to use babel-jest for both JavaScript and TypeScript files. Simply update your transform regex to the following.
// jest.config.js
module.exports = {
preset: "react-native",
transform: {
"^.+\\.[jt]sx?$": "babel-jest",
},
transformIgnorePatterns: ["node_modules/?!(react-icons)"],
setupFilesAfterEnv: ["<rootDir>/src/setupTests.ts"],
};
With that change, you can then uninstall ts-jest from your project since it will no longer be used.

ERROR TypeError: Cannot read property 'BrowserWindow' of undefined in angular version 10 and electron version 10 and ngx-electron 2.2.0

l have been trying to solve this error for the last 2 to 3 days.
I have a bigger program that gave me that so reproduced the error.
Steps to reproduce the error.
Install the latest version of angular cli version 10 to be precise.
Create an angular new project with ng new atatest.. Mine I called atatest.
Install the latest version of electron which is version 10.
Install the latest version of ngx-electron that is version 2.2.0
Create a main.js in the root directory of the project and populate it with the electron boiler plate
code.
I added import { NgxElectronModule } from 'ngx-electron'; in the app.module.ts and included
it in the NgModule.imports.
In the app.component.ts do the following:
i. Add ElectronService import { ElectronService } from 'ngx-electron';
ii. Then in the app.component.ts add the following:
brower: any;
constructor(private _electronService: ElectronService) {
this.browse = this._electronService.remote.BrowserWindow;
}
-> At this point I got: **ERROR TypeError: Cannot read property 'BrowserWindow' of null** which
also was the same when I tried it with any instance of electron including require which was
**ERROR TypeError: Cannot read property 'require' of null**
With that error I added nodeItegration to true in the main process that is main.js.
With that I got the following error:
ERROR TypeError: Cannot read property 'BrowserWindow' of undefined
I also tried to require electron in the index.html as the following but got the same error:
<script> const electron = require('electron'); </script>
I have written apps in the past in angular and electron and have never seen such a big problem. The
files are as follows:
a. Then the app.module.ts is:
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { NgxElectronModule } from 'ngx-electron';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
#NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
NgxElectronModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
b. The app.component.ts is:
import { Component, OnInit } from '#angular/core';
import { ElectronService } from 'ngx-electron';
#Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
browse: any;
constructor(private _electronService: ElectronService){
this.browse = this._electronService.remote.BrowserWindow;
}
title = 'atatest';
launch(){
let win: any;
win = new this.browse({
width: 800,
height: 600
});
win.loadURL('https://google.com');
}
ngOnInit(){
this.launch();
}
}
ln the package.json
{
"name": "atatest",
"version": "0.0.0",
"main": "main.js",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"electron": "electron ."
},
"private": true,
"dependencies": {
"#angular/animations": "~10.0.5",
"#angular/common": "~10.0.5",
"#angular/compiler": "~10.0.5",
"#angular/core": "~10.0.5",
"#angular/forms": "~10.0.5",
"#angular/platform-browser": "~10.0.5",
"#angular/platform-browser-dynamic": "~10.0.5",
"#angular/router": "~10.0.5",
"electron": "^10.1.1",
"electron-rebuild": "^2.0.1",
"ngx-electron": "^2.2.0",
"rxjs": "~6.5.5",
"sqlite3": "^5.0.0",
"tslib": "^2.0.0",
"zone.js": "~0.10.3"
},
"devDependencies": {
"#angular-devkit/build-angular": "~0.1000.4",
"#angular/cli": "~10.0.4",
"#angular/compiler-cli": "~10.0.5",
"#types/node": "^12.11.1",
"#types/jasmine": "~3.5.0",
"#types/jasminewd2": "~2.0.3",
"codelyzer": "^6.0.0",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~5.0.0",
"karma": "~5.0.0",
"karma-chrome-launcher": "~3.1.0",
"karma-coverage-istanbul-reporter": "~3.0.2",
"karma-jasmine": "~3.3.0",
"karma-jasmine-html-reporter": "^1.5.0",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~3.9.5"
}
}
13.In the main.js file we have:
const { app, BrowserWindow } = require ('electron');
const path = require ('path');
const url = require('url');
let win;
function createWindow(){
//create the browser window
win = new BrowserWindow({width: 800,
height: 600,
webPreferences: {nodeIntegration: true}
})
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/atatest/index.html'),
protocol: 'file:',
slashes: true,
webPreferences: {nodeIntegration: true}
}))
// Open the DevTools optionally:
win.webContents.openDevTools()
win.on('closed', ()=>{
win =null;
})
}
app.on('ready', createWindow);
The problem was that the Electron version 10 has remote disabled by default. l identified it by creating a new angular project and installing electron version 9 instead of 10.
I version 10 remote is disabled by default. You have to enable it manually in the electron entry file in my case main.js by setting enableRemoteModule to true in the webPreferences works like a charm and the error goes. The code is therefore modified as follows:
win = new BrowserWindow({width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
}
})

TypeScript, Apollo GraphQL yield not assignable" error for node-fetch

I'm working on implementing schema stitching in a NodeJS/Apollo/GraphQL project I'm working on. It's written in TypeScript.
The code is
import {
makeRemoteExecutableSchema,
introspectSchema,
mergeSchemas
} from 'graphql-tools';
import { HttpLink } from 'apollo-link-http';
import fetch from 'node-fetch';
export default async () => {
const link = new HttpLink({
uri:'http://localhost:4545',
fetch
})
const remoteSchema = await introspectSchema(link);
// Make remote executable schema
return makeRemoteExecutableSchema({
schema: remoteSchema,
link
});
}
and it's complaining that
.
The referenced section of the types file is
export interface HttpOptions {
uri?: string | UriFunction;
includeExtensions?: boolean;
fetch?: WindowOrWorkerGlobalScope['fetch'];
headers?: any;
credentials?: string;
fetchOptions?: any;
}
This seems to be a bug that has been fixed, but it doesn't seem fixed here, although I'm using the latest versions and the line
fetch?: WindowOrWorkerGlobalScope['fetch'];
does seem to be what is recommended for one of the workarounds, hence, it should be fixed.
For what it's worth, my package.json is
{
"dependencies": {
"apollo-datasource-graphql": "^1.3.2",
"apollo-datasource-rest": "^0.7.0",
"apollo-link-http": "^1.5.16",
"apollo-server": "^2.10.1",
"axios": "^0.19.2",
"dotenv": "^8.2.0",
"graphql": "^14.6.0",
"graphql-tools": "^4.0.7",
"https-proxy-agent": "^5.0.0",
"node-fetch": "^2.6.0",
"uuid": "^7.0.1"
},
"devDependencies": {
"#types/node": "^13.9.1",
"#types/ramda": "^0.26.43",
"babel-eslint": "^10.0.3",
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"pino": "^5.16.0",
"prettier": "^1.19.1",
"ramda": "^0.26.1",
"typescript": "^3.8.3"
},
"scripts": {
"dev": "tsc && node dist/index.js"
}
}
Any clues much appreciated!
Using cross-fetch will solve the issue.

webpack-hot-middleware throws error on HMR update - status.hot is undefined (cannot read property 'status' of undefined)

This is driving me nuts. I'm trying to set up HMR with hapi/hapi-webpack-plugin and webpack-hot-middleware. My set up is an APS.NE MVC 5 application (serving the data) and Aurelia as a front-end framework.
HMR seems to start properly:
Then when I make a change on any of my js/html files a rebuild is fired properly, again:
but I'm receiving an error in process-update.js where module.hot is undefined and naturally it will error out when it checks for module.hot.status()
Here are the relevant files:
webpack-dev-server.js
/* eslint no-console: 0 */
import {Server} from 'hapi';
import H2o2 from 'h2o2';
import yargs from 'yargs';
import Webpack from 'webpack';
import WebpackPlugin from 'hapi-webpack-plugin';
import webpackConfig from './webpack.config.babel';
const argv = yargs.argv;
const isNumeric = n => !isNaN(parseFloat(n)) && isFinite(n);
if (!isNumeric(argv.port)) {
console.log(`Port must be numeric`);
process.exit(-1);
}
const compiler = new Webpack(webpackConfig);
const server = new Server();
server.connection({ host: 'localhost', port: 6789, labels: 'proxy-server' });
const assets = {
publicPath: webpackConfig.output.publicPath,
hot: false,
noInfo: true,
quiet: false,
host: 'localhost',
port: 6790,
stats: {
colors: true,
},
};
const hot = {
log: console.log,
path: '/__webpack_hmr',
heartbeat: 10 * 1000,
};
server.register([
{
register: H2o2,
},
{
register: WebpackPlugin,
options: { compiler, assets, hot },
},
], error => {
if (error) {
return console.error(error);
}
server.route({
method: ['GET', 'POST'],
path: '/{path*}',
handler: (request, reply) => {
if (/^Content\/bundles\/[A-Za-z0-9\-]+\.css/.test(request.params.path)) {
const response = reply('// This is a fake CSS content... :)');
response.type('text/css');
return response;
}
return reply.proxy({
host: 'localhost',
port: argv.port,
passThrough: true,
});
},
});
server.start(() => console.log(`Server running on ${server.info.uri}`));
});
Package.json
{
"name": "aurelia-skeleton-navigation-webpack",
"version": "1.1.1",
"description": "A starter kit for building a standard navigation-style app with Aurelia and webpack.",
"main": "dist/main.js",
"scripts": {
...
"start": "babel-node ./webpack-dev-server.js"
...
},
],
"aurelia": {
"build": {
"resources": []
}
},
"dependencies": {
"aurelia-bootstrapper-webpack": "^1.1.0",
"aurelia-event-aggregator": "^1.0.0",
"aurelia-fetch-client": "^1.0.1",
"aurelia-framework": "^1.0.7",
"aurelia-history-browser": "^1.0.0",
"aurelia-http-client": "^1.0.3",
"aurelia-loader-webpack": "^1.0.3",
"aurelia-logging-console": "^1.0.0",
"aurelia-pal-browser": "^1.0.0",
"aurelia-polyfills": "^1.1.1",
"aurelia-route-recognizer": "^1.1.0",
"aurelia-router": "^1.0.7",
"aurelia-templating-binding": "^1.1.0",
"aurelia-templating-resources": "^1.2.0",
"aurelia-templating-router": "^1.0.0",
"aurelia-ui-virtualization": "1.0.0-beta.3.0.0",
"babel-polyfill": "^6.20.0",
"bootstrap": "^3.3.7",
"d3": "^4.4.0",
"font-awesome": "^4.7.0",
"highcharts": "^5.0.6",
"isomorphic-fetch": "^2.2.1",
"select2": "3.5.1"
},
"devDependencies": {
"#easy-webpack/config-aurelia": "^2.2.2",
"#easy-webpack/config-babel": "^4.0.0",
"#easy-webpack/config-common-chunks-simple": "^2.0.3",
"#easy-webpack/config-copy-files": "^1.1.2",
"#easy-webpack/config-css": "^4.0.0",
"#easy-webpack/config-env-development": "^2.1.5",
"#easy-webpack/config-env-production": "^3.0.0",
"#easy-webpack/config-external-source-maps": "^3.1.0",
"#easy-webpack/config-fonts-and-images": "^2.1.0",
"#easy-webpack/config-generate-index-html": "^2.1.1",
"#easy-webpack/config-global-bluebird": "^2.1.0",
"#easy-webpack/config-global-jquery": "^2.1.0",
"#easy-webpack/config-global-regenerator": "^1.2.2",
"#easy-webpack/config-html": "^3.1.0",
"#easy-webpack/config-json": "^3.1.0",
"#easy-webpack/config-test-coverage-istanbul": "^3.2.0",
"#easy-webpack/config-uglify": "^2.2.3",
"#easy-webpack/core": "^2.0.0",
"aurelia-tools": "^1.0.0",
"babel-cli": "^6.4.5",
"babel-loader": "^6.2.8",
"babel-plugin-transform-class-properties": "^6.18.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-env": "^1.0.0",
"babel-register": "^6.18.0",
"concurrently": "^3.1.0",
"cross-env": "^3.1.3",
"del-cli": "^0.2.0",
"eslint": "^3.12.0",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.8.5",
"h2o2": "^5.4.0",
"hapi": "^16.0.2",
"hapi-webpack-plugin": "^1.3.0",
"html-webpack-plugin": "^2.24.1",
"http-server": "^0.9.0",
"install": "^0.8.2",
"jasmine-core": "^2.5.2",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.0.2",
"karma-mocha-reporter": "^2.2.0",
"karma-remap-istanbul": "^0.2.1",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.0",
"node-sass": "^4.1.0",
"npm": "^4.0.3",
"optimize-css-assets-webpack-plugin": "^1.3.0",
"postcss-cssnext": "^2.9.0",
"postcss-import": "^9.0.0",
"postcss-loader": "^1.2.1",
"protractor": "^4.0.11",
"sass-loader": "^4.1.0",
"url-loader": "^0.5.7",
"wait-on": "^2.0.1",
"webpack": "2.1.0-beta.27",
"webpack-dev-server": "2.1.0-beta.12",
"yargs": "^3.32.0",
"babel-preset-es2015": "^6.3.13",
"bootstrap": "^3.3.6",
"clean-webpack-plugin": "^0.1.8",
"css-loader": "^0.23.1",
"font-awesome": "^4.5.0",
"strip-loader": "^0.1.2",
"style-loader": "^0.13.0"
}
}
webpack.confing.babel.js
/**
* To learn more about how to use Easy Webpack
* Take a look at the README here: https://github.com/easy-webpack/core
**/
import { generateConfig, get, stripMetadata, EasyWebpackConfig } from '#easy-webpack/core'
import path from 'path'
...
process.env.BABEL_ENV = 'webpack';
const ENV = process.env.NODE_ENV && process.env.NODE_ENV.toLowerCase() || (process.env.NODE_ENV = 'development');
// basic configuration:
const title = 'Aurelia Navigation Skeleton';
const baseUrl = '.';
const rootDir = path.resolve();
const srcDir = path.resolve('src');
const outDir = path.resolve('dist');
let htmlWebPackPlugin = new HtmlWebpackPlugin({
inject: false,
template: 'Areas/Aurelia/Views/Shared/_AureliaLayoutTemplate.cshtml',
filename: '../Areas/Aurelia/Views/Shared/_AureliaLayout.cshtml'
});
let optimizeCssAssetsPlugin = new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css$/,
cssProcessorOptions: { discardComments: { removeAll: true } }
});
let plugins = ENV === 'production'
? { plugins: [htmlWebPackPlugin, optimizeCssAssetsPlugin] }
: { plugins: [htmlWebPackPlugin, new webpack.HotModuleReplacementPlugin(), new webpack.NoErrorsPlugin() ] };
const coreBundles = {
bootstrap: [
'aurelia-bootstrapper-webpack',
'aurelia-polyfills',
'aurelia-pal',
'aurelia-pal-browser',
'regenerator-runtime'
],
// these will be included in the 'aurelia' bundle (except for the above bootstrap packages)
aurelia: [
'aurelia-bootstrapper-webpack',
'aurelia-binding',
'aurelia-dependency-injection',
'aurelia-event-aggregator',
'aurelia-framework',
'aurelia-history',
'aurelia-history-browser',
'aurelia-loader',
'aurelia-loader-webpack',
'aurelia-logging',
'aurelia-logging-console',
'aurelia-metadata',
'aurelia-pal',
'aurelia-pal-browser',
'aurelia-path',
'aurelia-polyfills',
'aurelia-route-recognizer',
'aurelia-router',
'aurelia-task-queue',
'aurelia-templating',
'aurelia-templating-binding',
'aurelia-templating-router',
'aurelia-templating-resources',
'aurelia-ui-virtualization',
'select2',
'webpack-hot-middleware/client',
'webpack/hot/only-dev-server'
]
}
/**
* Main Webpack Configuration
*/
let config = generateConfig(
{
entry: {
'app': ['./src/main' /* this is filled by the aurelia-webpack-plugin */,
'webpack-hot-middleware/client',
'webpack/hot/only-dev-server'],
'aurelia-bootstrap': coreBundles.bootstrap,
'aurelia': coreBundles.aurelia.filter(pkg => coreBundles.bootstrap.indexOf(pkg) === -1)
},
output: {
path: outDir,
publicPath: '/dist/'
},
...
module.exports = stripMetadata(config);
Am I missing something in the config that leaves module.hot property undefined?
I'm answering my own question for posterity:
This is related to my other question:
Aurelia, running webpack-dev-server --hot throws error on App Hot Update - 'Cannot read property 'status' of undefined'
In short, Aurelia doesn't support HMR ... yet (only css).
https://github.com/aurelia/skeleton-navigation/issues/629
http://blog.aurelia.io/2016/12/08/big-aurelia-release-update/

router_1.provideRouter is not a function when trying to run Angular2/NodeJS app

I have created a simple NodeJS/Angular2 application which is encountering the following error when I try and access the entry point page for the application:
router_1.provideRouter is not a function
I am unsure as to what this error means and have no idea where to start. Does anyone have any insight or idea as to why this may be happening? Here is my package.json file (as I am thinking it may be something to do with one of the Angular packages)
{
"name": "udemy-nodejs-angular2",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "concurrently tsc -w && nodemon ./bin/www",
"vendor": "gulp vendor",
"gulp": "npm run vendor && gulp",
"postinstall": "typings install",
"typings": "typings"
},
"dependencies": {
"#angular/common": "^2.0.0-rc.2",
"#angular/compiler": "^2.0.0-rc.2",
"#angular/core": "^2.0.0-rc.2",
"#angular/http": "2.0.0-rc.2",
"#angular/platform-browser": "^2.0.0-rc.2",
"#angular/platform-browser-dynamic": "^2.0.0-rc.2",
"#angular/router": "3.0.0-beta.2",
"#angular/upgrade": "2.0.0-rc.2",
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"es6-shim": "^0.35.0",
"express": "~4.13.1",
"hbs": "~3.1.0",
"morgan": "~1.6.1",
"reflect-metadata": "^0.1.3",
"rxjs": "^5.0.0-beta.6",
"serve-favicon": "~2.3.0",
"systemjs": "0.19.27",
"zone.js": "^0.6.12"
},
"devDependencies": {
"concurrently": "^2.2.0",
"gulp": "^3.9.0",
"gulp-sourcemaps": "^1.6.0",
"gulp-typescript": "^2.10.0",
"nodemon": "^1.9.2",
"typings": "^0.8.1"
}
}
and my SystemJS config:
// map tells the System loader where to look for things
var map = {
'app': 'js/app', // 'dist',
'rxjs': 'js/vendor/rxjs',
'#angular': 'js/vendor/#angular'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': {main: 'boot.js', defaultExtension: 'js'},
'rxjs': {defaultExtension: 'js'}
};
var packageNames = [
'#angular/common',
'#angular/compiler',
'#angular/core',
'#angular/http',
'#angular/platform-browser',
'#angular/platform-browser-dynamic',
'#angular/router',
'#angular/testing',
'#angular/upgrade'
];
// add package entries for angular packages in the form '#angular/common': { main: 'index.js', defaultExtension: 'js' }
packageNames.forEach(function (pkgName) {
packages[pkgName] = {main: 'index.js', defaultExtension: 'js'};
});
var config = {
map: map,
packages: packages
};
System.config(config);
Here are the places I am using the router functionality:
app.routes.ts
import {provideRouter, RouterConfig} from '#angular/router';
import {LoginComponent} from "./components/login/login.component";
import {DashboardComponent} from "./components/dashboard/dashboard.component";
export const routes: RouterConfig = [
{ path: 'login', component: LoginComponent },
{ path: 'dashboard', component: DashboardComponent }
];
export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];
boot.ts:
import {bootstrap} from '#angular/platform-browser-dynamic';
import {AppComponent} from "./app.component";
import { APP_ROUTER_PROVIDERS } from './app.routes';
bootstrap(AppComponent, [
APP_ROUTER_PROVIDERS
])
.catch(err => console.error(err));
app.component.ts
import { Component } from '#angular/core';
import { ROUTER_DIRECTIVES } from '#angular/router';
#Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: 'app.template.html',
directives: [
ROUTER_DIRECTIVES
]
})
export class AppComponent {
}
Thanks
As we found out in the chat, the problem was that the router in the vendor folder didn't get updated to the new version.
To solve this problem, the router under the vendor folder must be deleted, then and npm install should be run and finally a npm run gulp recreated the vendor folder.

Resources