I need to include jwt-simple into a test so that I can generate JWT tokens and validate the UI does what it needs to do given certain scenarios.
I have tried npm install jwt-simple and then import jwt from 'jwt-simple/jwt'; and import jwt from 'jwt-simple'; but neither work.
Should I be able to import node packages into the tests like this?
As jwt-simple is not an ember addon, you cannot import the module like this in an ember-cli setup. To import an npm module which is not an ember addon, you will need ember-browserify. So install ember-browserify first:
npm install --save-dev ember-browserify
Then import the module as follows:
import jwt from 'npm:jwt-simple';
Related
I recently upgraded my project to use the #hapi/hapi node modules vs. the old hapi module. I'm using version 18.3.1 ("#hapi/hapi": "^18.3.1").
My Typescript definitions no longer work as the Import reads: import * as Hapi from 'hapi';
When running the node process I get the module not found error. Is there a way to point the #types/hapi typings to the new #hapi/hapi module?
Uninstall the #types/hapi dependency. This didn't work for me moving to 18.3.1. Instead install #types/hapi__hapi. I searched for a while and ran across that package, which seems to do the trick.
npm un #types/hapi -D
npm i #types/hapi__hapi -D
Then instead of importing from 'hapi', import from '#hapi/hapi'.
import * as Hapi from '#hapi/hapi';
I installed react-awesome-query-builder from branch antd-3 but after import on react file, there is an error that says:
import {Query, Builder, Utils as QbUtils} from 'react-awesome-query-builder';
Error :
Failed to compile ./src/shared/queryBuilder/QueryBuilder.js
Module not found: Can't resolve 'react-awesome-query-builder' in 'D:\manshoor_ui\src\shared\queryBuilder'
This module is added to package.json and node_modules but there is this error. I installed by this command:
npm install --save ukrbublik/react-awesome-query-builder#antd-3
So what might be wrong here?
According to github docs documentation for that package, it's supposed to be installed like this:
npm i react-awesome-query-builder
And then you import it like this:
import {Query, Builder, Utils} from 'react-awesome-query-builder';
I know that NodeJS is important when using npm to download modules but does react depends from it? For example i have a react app created from create-react-app and i have this part:
import ReactDOM from 'react-dom';
import './index.css';
Is nodeJs used to configure the paths in the files or is it just the babel compiler that does that?
If yes, is babel configured to look in the node_modules files like NodeJs does?
Babel is unaware of modules. It is the responsibility of a bundler (Webpack in create-react-app) to handle module imports.
Webpack resolver works similarly to Node resolver regarding node_modules, this can be configured.
I'm trying to run the following code with ts-node.
import { writeFileSync, readFileSync } from 'fs';
However I get:
src/main/ts/create.ts (1,45): Cannot find module 'fs'. (2307)
What do I need to do in to allow typescript to import the fs module?
You need to run:
$ npm install #types/node --save-dev
If you need additional information you can refer to the NodeJS QuickStart in the TypeScript Deep Dive by Basarat.
I have a very simple Ionic2 project with some providers that import pouchdb library.
import * as PouchDB from 'pouchdb';
I want to access pouchdb from the console somehow. How can I get that working?
I want to access pouchdb from the console somehow.
Assuming that you installed the pouchdb dependency by running
npm install pouchdb --save
And then (optional but recommended) installed typings as well
npm install -g typings
typings install --global --save dt~pouchdb dt~pouchdb-adapter-websql dt~pouchdb-browser dt~pouchdb-core dt~pouchdb-http dt~pouchdb-mapreduce dt~pouchdb-node dt~pouchdb-replication
Just like you said, you need to import it in your code
import * as PouchDB from 'pouchdb';
And then use the new PouchDB('aName') method to get an instance of the db. Then you can just use that instance in the console.
#Injectable()
export class MyDbClass {
db: any;
constructor() {
this.initializeDb();
}
initializeDb(){
this.db = new PouchDB('aName');
console.log(this.db);
}