将 pouchdb 导入 angular4
importing pouchdb into angular4
问题:
无法在 angular4 中导入 pouchdb
运行ning ng serve in angular cli(应该编译打字稿并制作页面 运行)给出错误
使用 pouchddb 时
Cannot find module 'pouchdb'. webpack: Failed to compile.
并且在使用 pouchdb-browswer 时
Cannot find module 'pouchdb-browser'. webpack: Failed to compile.
复制
1- 安装 angular cli
npm install angluar-cli -g
2- 创建 angular 项目
ng new project
3- 在项目中安装 pouch
或者
npm install pouchdb --save
或
npm install pouchdb-browser --save
在代码中import pouch db
尝试了其中的每一个,但都给出了相同的错误
import PouchDB from 'pouchdb';
import PouchDB from 'pouchdb-browser';
import * as PouchDB from 'pouchdb-browser';
import * as PouchDB from 'pouchdb';
备注
安装@types/pouchdb 没有帮助,事实上我得到了更多的编译错误
一些错误是
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (765,30): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (766,37): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (767,40): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (768,33): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (771,30): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (772,37): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (773,41): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (776,30): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (777,37): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (778,33): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-replication/index.d.ts (166,45): '>' expected.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-replication/index.d.ts (166,47): Expression expected.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-replication/index.d.ts (186,13): ',' expected.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-replication/index.d.ts (191,10): ',' expected.
更新
我尝试从 'pouchdb' 导入 PouchDB;在普通的打字稿文件中(非 angular)
并用 tsc 编译它并且工作正常
我猜这个问题是因为 angular-cli 或 webpack 不确定
将 CLI v1.2.0 与 Angular v4.3.3 和 import PouchDB from 'pouchdb';
一起使用对我有用。
请记住,该软件包在某个时候已重命名,只有较新的版本才支持更高级的 webpack 配置。
如果您使用的是 Typescript(Angular 或 ionic),请确保您 运行 这些命令
npm install pouchdb @types/pouchdb
并在 tsconfig.json 文件中添加 "allowSyntheticDefaultImports": true
。
{
"compilerOptions": {
"allowSyntheticDefaultImports": true
}
}
然后使用
导入您的供应商
import PouchDB from 'pouchdb';
问题:
无法在 angular4 中导入 pouchdb 运行ning ng serve in angular cli(应该编译打字稿并制作页面 运行)给出错误
使用 pouchddb 时
Cannot find module 'pouchdb'. webpack: Failed to compile.
并且在使用 pouchdb-browswer 时
Cannot find module 'pouchdb-browser'. webpack: Failed to compile.
复制
1- 安装 angular cli
npm install angluar-cli -g
2- 创建 angular 项目
ng new project
3- 在项目中安装 pouch 或者
npm install pouchdb --save
或
npm install pouchdb-browser --save
在代码中import pouch db
尝试了其中的每一个,但都给出了相同的错误
import PouchDB from 'pouchdb';
import PouchDB from 'pouchdb-browser';
import * as PouchDB from 'pouchdb-browser';
import * as PouchDB from 'pouchdb';
备注
安装@types/pouchdb 没有帮助,事实上我得到了更多的编译错误 一些错误是
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (765,30): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (766,37): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (767,40): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (768,33): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (771,30): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (772,37): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (773,41): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (776,30): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (777,37): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-core/index.d.ts (778,33): Cannot find namespace 'Core'.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-replication/index.d.ts (166,45): '>' expected.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-replication/index.d.ts (166,47): Expression expected.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-replication/index.d.ts (186,13): ',' expected.
ERROR in C:/Users/aallawati/Development/pro1/node_modules/@types/pouchdb-replication/index.d.ts (191,10): ',' expected.
更新
我尝试从 'pouchdb' 导入 PouchDB;在普通的打字稿文件中(非 angular)
并用 tsc 编译它并且工作正常
我猜这个问题是因为 angular-cli 或 webpack 不确定
将 CLI v1.2.0 与 Angular v4.3.3 和 import PouchDB from 'pouchdb';
一起使用对我有用。
请记住,该软件包在某个时候已重命名,只有较新的版本才支持更高级的 webpack 配置。
如果您使用的是 Typescript(Angular 或 ionic),请确保您 运行 这些命令
npm install pouchdb @types/pouchdb
并在 tsconfig.json 文件中添加 "allowSyntheticDefaultImports": true
。
{
"compilerOptions": {
"allowSyntheticDefaultImports": true
}
}
然后使用
导入您的供应商import PouchDB from 'pouchdb';