I'm building an Ionic 2 (RC0) application and I'm trying to use node-uuid by following the official documentation.
I've done:
$ npm install --save node-uuid
$ npm install --save #types/node-uuid
node-uuid seems to be using the default export approach, so I'm importing it in my typescript file like this:
import uuid from 'node-uuid';
And using it as follows:
console.log(uuid.v4);
However, my app doesn't come up and I see this error in the logs:
TypeError: des$3 is undefined
What am I missing?
Most resources for Angular 2 recommend using the typings CLI to install the type definitions, but this made no difference for me. I tried:
$ npm install --global typings
$ typings install --save node-uuid
$ ionic info
Your system information:
Cordova CLI: You have been opted out of telemetry. To change this, run: cordova telemetry on.
6.3.1
Ionic Framework Version: 2.0.0-rc.0
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.1.0-beta.1
OS: Distributor ID: Ubuntu Description: Ubuntu 16.04.1 LTS
Node Version: v6.6.0
******************************************************
Dependency warning - for the CLI to run correctly,
it is highly recommended to install/upgrade the following:
Please install your Cordova CLI to version >=4.2.0 `npm install -g cordova`
******************************************************
Please note that node-uuid is deprecated. They merged with another project and now it's only called uuid. Everything up to the point of installing the #types library is correct. (note that you will have to redo those steps using just 'uuid' not 'nod-uuid')
However,
console.log(uuid.v4);
does not generate an id. As per the documentation you need to specify in your import which version of uuid you want to use and then call your variable as a method: uuid();
From docs: [Deprecation warning: The use of require('uuid') is deprecated and will not be supported after version 3.x of this module. Instead, use require('uuid/[v1|v3|v4|v5]') as shown in the examples below.]
Here is a code example using uuid/v1:
import { Component } from '#angular/core';
import uuid from 'uuid/v1'; //here change 'v1' with the version you desire to use
#Component({
selector: "page-uuid",
templateUrl: "uuid.html"
})
export class uuidTestPage {
id = uuid();
constructor() {
console.log(this.id); // outputs id. For example: 298da400-1267-11e8-a6e5-3148ee6706e9
}
}
After you serve your app and enter the uuidTestPage you should see the id logged to the console. The format of the id will vary depending on the version you use:
Version 1 (timestamp): my example.
Version 3 (namespace)
Version 4 (random)
etc...
Happy coding!
you can try it: (angular2-uuid)
npm install angular2-uuid --save
......
import { UUID } from 'angular2-uuid';
...
let uuid = UUID.UUID();
it works on angular 2 & ionic 2
Related
I just started playing around with AWS CDK yesterday and I found something very weird.
First of all, I'm using TypeScript for my CDK app (I used cdk init --language typescript to generate the project files and I tried to import aws-ec2 module so this is what I did:
import cdk = require('#aws-cdk/core');
import ec2 = require('#aws-cdk/aws-ec2');
export class vpcStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
//.... all other codes go here....
However, when importing the aws-ec2 module this way, I got this error when trying to deploy the stack:
⨯ Unable to compile TypeScript:
lib/cdk-type_script-stack.ts:2:22 - error TS2307: Cannot find module '#aws-cdk/aws-ec2'.
2 import ec2 = require('#aws-cdk/aws-ec2');
~~~~~~~~~~~~~~~~~~
Subprocess exited with error 1
This is very weird because the API docs right here clearly stated that this is how I should import the aws-ec2 module in TypeScript
You need to install the node package before you could import and use it
Execute below on the command line to install npm package for aws-cdk
npm i #aws-cdk/aws-ec2
npm install (for install lib)
npm run build (for compile your code)
After that, you can run:
cdk synth
cdk deploy
You may have a version of npm that is incompatible with the version of #aws-cdk/pipelines as explained here: https://github.com/aws/aws-cdk/issues/13541#issuecomment-801606777
In addition to #juned-ashan 's answer, verify that you are installing the correct module version that corresponds to your cdk version (and other cdk modules installed).
For example:
$ npm install --save #aws-cdk/aws-ec2#1.10.0
Note: not enough points to add this as a comment in Juned's answer.
I am using ionic2 build .
I did ionic plugin add cordova-plugin-file and used following code.
import {File} from 'ionic-native';
#Injectable()
export class GlobalVars {
constructor(platform:Platform) {
platform.ready().then(() => {
this.appRootFolder = cordova.file.documentsDirectory;
}
}
}
then I did ionic build android and I got this error
Cannot find name 'cordova'
After 2 hour of struggling , I resolved the issues by following commands
npm install -g typings
typings install dt~cordova --save --global
typings install dt~cordova/plugins/filesystem --save --global
This helped in building android , but still fails for iOS. when I run this ionic build ios I still get
Cannot find name 'cordova'
I wrote this line(declare var cordova:any;) at the top of file
import {File} from 'ionic-native';
declare var cordova:any;
And the problem is solved for me.
As of lately, you can do this:
In CLI, from your project folder:
ionic plugin add cordova-plugin-file
Then, in your component/class file:
import { File } from 'ionic-native';
declare var cordova: any;
const fs:string = cordova.file.dataDirectory;
File.checkDir(this.fs, 'mydir')
.then(_ => console.log('yay'))
.catch(err => console.log('boooh'));
Many native plugins are now well implemented and documented by the Ionic Team :)
Source: Ionic Native docs
Try copying cordova.d.ts file and plugins folder from here - https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/cordova230
And paste this folder and file in your project/typings directory.
UPDATE 2
I've filed an issue at the ember-cli repo describing simple steps to reproduce the issue: https://github.com/ember-cli/ember-cli/issues/4015.
UPDATE
This is related to using in-repo-addons. The ember compiler does not choke when using this syntax in your regular app. I will be filing a bug report at http://github.com/ember-cli/ember-cli shortly with steps to reproduce and will link back to the issue here when it is ready.
I caught the bug for es6 and started using the object literal method shorthand:
import Ember from 'ember';
export default Ember.Component.extend({
didInsertElement() {
// stuff I want to do once we're in the DOM
}
})
but it chokes when running ember build --environment production. Thoughts?
Build failed.
Unexpected token punc «(», expected punc «:»
Ember-cli uses babel which does support object literal shorthands.
See:
https://babeljs.io/docs/learn-es6/
In Repo Addons (currently) require ember-cli-babel as a dependency.
$ cd lib/<your addon>
$ npm install ember-cli-babel --save
$ cd ../..
$ ember build --environment production
i'm using ember-cli version 0.1.15 and it fails to run a newly created ember app.
Here are the commands issued to install ember-cli and to create the new app:
$ npm uninstall -g ember-cli
$ npm cache clean
$ bower cache clean
$ npm install -g ember-cli#0.1.15
$ ember new Query
$ cd Query
$ ember serve
While the ember service starts up, it attempts to parse the jquery intro.js file which is a partial module file because it does not close the IIFE function. I guess the outro.js file is the companion file that closes the intro.js.
Below is the resulting error after invoking ember serve
version: 0.1.15
Livereload server on port 35729
Serving on http://0.0.0.0:4200/
File: bower_components/jquery/src/intro
Unexpected token (45:0)
SyntaxError: Unexpected token (45:0)
at raise (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:333:15)
at unexpected (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:1366:5)
at parseExprAtom (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:2153:7)
at parseExprSubscripts (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:2012:28)
at parseMaybeUnary (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:1995:16)
at parseExprOps (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:1946:24)
at parseMaybeConditional (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:1930:16)
at parseMaybeAssign (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:1913:16)
at parseExpression (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:1898:16)
at parseStatement (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:1586:38)
at parseBlock (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:1826:18)
at parseFunctionBody (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:2378:19)
at parseFunction (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:2277:5)
at parseExprAtom (/Users/Steffen/Temp/Query/node_modules/ember-cli/node_modules/broccoli-es6modules/node_modules/esperanto/node_modules/acorn/acorn.js:2141:14)
I tried reinstalling ember-cli and clearing the npm and bower caches. Any other caches that need to be cleared?
Try not capitalizing the new ember app's name:
ember new query
Also, you don't need to specify the ember cli version:
npm install -g ember-cli
In case query is a reserved keyword, if you still get errors, try another name.
I am learning to configure Laravel Echo Socket.js and following an article here
Code in bootstrap.js is below
import Echo from "laravel-echo"
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001'
});
When I run the above code, it says, Cannot find module "laravel-echo"
I am not using pusher and redis. In the above reference page, I think, there is no installation guidelines given for only socket.io
Can somebody explain if I am missing anything?
I solved the same problem installing the following packages:
npm install --save laravel-echo pusher-js
I needed to install below packages.
npm install -g laravel-echo-server
then following the step by step instruction as give here
Finally put below code before any js file.
<script src="http://{{ Request::getHost() }}:6001/socket.io/socket.io.js"></script>
the issue is here:-
import Echo from "laravel-echo"
you will write it as:-
import Echo from 'laravel-echo';