无法在angular4中导入pouchdb 在angular cli中运行ng服务(应编译typescript并使页面运行)会产生错误
使用pouchddb时
找不到模块'pouchdb'。 webpack:无法编译。
使用pouchdb-browswer时
找不到模块'pouchdb-browser'。 webpack:无法编译。
1-安装angular cli
npm install angluar-cli -g
2-创建角度项目
ng new project
3-在项目安装袋中 任
npm install pouchdb --save
或
npm install pouchdb-browser --save
在代码导入包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;在普通的打字稿文件(非角度)
并使用tsc编译它并且工作正常
我想问题是因为angular-cli或webpack不确定
答案 0 :(得分:1)
如果您正在使用Typescript(角度或离子),请确保运行以下命令
npm install pouchdb @types/pouchdb
,然后在您的tsconfig.json文件中添加"allowSyntheticDefaultImports": true
。
{
"compilerOptions": {
"allowSyntheticDefaultImports": true
}
}
然后使用
导入您的提供商import PouchDB from 'pouchdb';
答案 1 :(得分:0)
将CLI v1.2.0与Angular v4.3.3和import PouchDB from 'pouchdb';
一起使用对我有用。
请记住,软件包已在某个位置重命名,只有较新版本支持更高级的Webpack配置。