过去几天我一直有这个问题,并且能够在今天缩小罪魁祸首:
从一个全新的项目开始,并向其添加firebase
:
ionic start -a "MyApp" -i com.package.xyz MyApp tabs --v2
npm install --save firebase
此时,ionic serve
正常工作。但是如果我在任何文件中导入firebase
:
import firebase from 'firebase';
现在运行ionic serve --debug
会引发以下错误:
******************************************************
Dependency warning - for the CLI to run correctly,
it is highly recommended to install/upgrade the following:
Install ios-sim to deploy iOS applications.`npm install -g ios-sim` (may require sudo)
Install ios-deploy to deploy iOS applications to devices. `npm install -g ios-deploy` (may require sudo)
******************************************************
> ionic-hello-world@ ionic:serve /Users/Desktop/Projects/MyApp
> ionic-app-scripts serve "--debug"
[13:27:37] ionic-app-scripts 0.0.45
[ DEBUG! ] An BuildUpdateStarted event occurred MEM: 116.7MB
[ DEBUG! ] An BuildUpdateCompleted event occurred MEM: 116.7MB
[ DEBUG! ] An FileChange event occurred MEM: 116.9MB
[ DEBUG! ] An ReloadApp event occurred MEM: 116.9MB
[13:27:38] watch started ... MEM: 117.2MB
[13:27:38] build dev started ... MEM: 117.2MB
[13:27:38] clean started ... MEM: 117.2MB
[ DEBUG! ] clean /Users/Desktop/Projects/MyApp/www/build MEM: 117.2MB
[13:27:38] clean finished in 6 ms MEM: 117.4MB
[13:27:38] copy started ... MEM: 117.4MB
[13:27:38] transpile started ... MEM: 117.5MB
[13:27:42] build dev failed: Cannot read property 'indexOf' of undefined MEM: 253.7MB
[ DEBUG! ] TypeError: Cannot read property 'indexOf' of undefined at loadDiagnostic
(/Users/Desktop/Projects/MyApp/node_modules/@ionic/app-scripts/dist/logger/logger-typescript.js:47:27)
at
/Users/Desktop/Projects/MyApp/node_modules/@ionic/app-scripts/dist/logger/logger-typescript.js:12:16
at Array.map (native) at Object.runTypeScriptDiagnostics
(/Users/Desktop/Projects/MyApp/node_modules/@ionic/app-scripts/dist/logger/logger-typescript.js:11:26)
at /Users/Desktop/Projects/MyApp/node_modules/@ionic/app-scripts/dist/transpile.js:92:47 at
transpileWorker
(/Users/Desktop/Projects/MyApp/node_modules/@ionic/app-scripts/dist/transpile.js:62:12) at
Object.transpile
(/Users/Desktop/Projects/MyApp/node_modules/@ionic/app-scripts/dist/transpile.js:26:12) at
buildDev
(/Users/Desktop/Projects/MyApp/node_modules/@ionic/app-scripts/dist/build.js:84:24) at
buildWorker
(/Users/Desktop/Projects/MyApp/node_modules/@ionic/app-scripts/dist/build.js:35:12) at
Object.build
(/Users/Desktop/Projects/MyApp/node_modules/@ionic/app-scripts/dist/build.js:19:12)
MEM: 253.7MB
[ DEBUG! ] listening on 8100 MEM: 253.9MB
[ DEBUG! ] watcher ready:
/Users/Desktop/Projects/MyApp/Users/Desktop/Projects/MyApp/src/assets/,/Users/Desktop/Projects/MyApp/src/index.html,/Users/Desktop/Projects/MyApp/src/manifest.json,/Users/Desktop/Projects/MyApp/src/service-worker.js,node_modules/ionic-angular/polyfills/polyfills.js,node_modules/ionicons/dist/fonts/
MEM: 253.8MB
[13:27:42] copy finished in 3.69 s MEM: 253.8MB
[ DEBUG! ] watcher ready:
/Users/Desktop/Projects/MyApp/Users/Desktop/Projects/MyApp/src/**/*.(ts|html|scss)
MEM: 253.8MB
[13:27:42] watch ready in 3.70 s MEM: 253.8MB
[13:27:42] dev server running: http://localhost:8100/
如果我删除导入,ionic serve
可以再次正常工作。
以下是ionic info
的输出:
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.3
Ionic CLI Version: 2.1.14
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.45
ios-deploy version: Not installed
ios-sim version: Not installed
OS: macOS Sierra
Node Version: v6.7.0
Xcode version: Not installed
如何更正此错误?
阿西
修改
我在上一节中将错误追溯到node_modules/firebase/firebase.d.ts
,其中包含:
declare module 'firebase' {
export = firebase;
}
为此,编译器抱怨:Duplicate identifier 'export='.
如果我删除此部分或export = firebase;
行,则错误消失且ionic serve
正常工作,但我无法访问firebase
对象。
更奇怪的是,如果我从一个仅添加了firebase
的空白项目开始,并运行ionic serve
,那么事情就可以了。接下来,我在我的一个源文件中导入firebase
,一切正常。直到我终止ionic serve
并重新启动它。此时,我得到与帖子顶部附近列出的错误相同的错误。
我甚至更新了node
,ionic
,cordova
和ionic-app-scripts
。 ionic info
现在显示:
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.3
Ionic CLI Version: 2.1.14
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.46
ios-deploy version: Not installed
ios-sim version: Not installed
OS: macOS Sierra
Node Version: v6.9.1
Xcode version: Not installed
但仍然是同一个问题。我迫切需要帮助来解决这个问题.. = /
修改
欲了解更多信息:
tsconfig.json
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": [
"dom",
"es2015"
],
"module": "es2015",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules"
],
"compileOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
的package.json
{
"name": "ionic-hello-world",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "2.1.1",
"@angular/compiler": "2.1.1",
"@angular/compiler-cli": "2.1.1",
"@angular/core": "2.1.1",
"@angular/forms": "2.1.1",
"@angular/http": "2.1.1",
"@angular/platform-browser": "2.1.1",
"@angular/platform-browser-dynamic": "2.1.1",
"@angular/platform-server": "2.1.1",
"@ionic/app-scripts": "0.0.46",
"@ionic/storage": "1.1.6",
"firebase": "^3.6.2",
"ionic-angular": "2.0.0-rc.3",
"ionic-native": "2.2.3",
"ionicons": "3.0.0",
"lodash": "^4.17.2",
"rxjs": "5.0.0-beta.12",
"uuid": "^3.0.1",
"zone.js": "0.6.26"
},
"devDependencies": {
"@ionic/app-scripts": "0.0.45",
"typescript": "2.0.6"
},
"cordovaPlugins": [
"cordova-plugin-whitelist",
"cordova-plugin-statusbar",
"cordova-plugin-console",
"cordova-plugin-device",
"cordova-plugin-splashscreen",
"ionic-plugin-keyboard"
],
"cordovaPlatforms": [
"ios",
{
"platform": "ios",
"version": "",
"locator": "ios"
}
],
"description": "An Ionic project"
}
npm版本
npm@3.10.8
cordova@6.4.0
ionic@2.1.14
typescript@2.0.10
firebase@3.6.2
答案 0 :(得分:0)