开发者问题收集

IONIC 3 项目无法正常工作

2017-12-16
359
  ng build --prod
    Date: 2017-12-16T12:11:38.469Z
    Hash: 9af9d0824b91129853ac
    Time: 3766ms
    chunk {0}  (styles) [initial] [rendered]
    chunk {1} polyfills.bf31271ed8358d9c1c6b.bundle.js (polyfills) 155 bytes [initial] [rendered]
    chunk {2} main.a0f3445c4f3c97baab24.bundle.js (main) 149 bytes [initial] [rendered]
    chunk {3} inline.c30c9795283a00740af2.bundle.js (inline) 1.45 kB [entry] [rendered]

    ERROR in multi ./src/main.ts
    Module not found: Error: Can't resolve '/Users/tyyiu/Documents/Code/IONIC/quorra/src/main.ts' in '/Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@angular/c
    li/models/webpack-configs'
    resolve '/Users/tyyiu/Documents/Code/IONIC/quorra/src/main.ts' in '/Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@angular/cli/models/webpack-configs'
      using description file: /Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@angular/cli/package.json (relative path: ./models/webpack-configs)
        Field 'browser' doesn't contain a valid alias configuration

      after using description file: /Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@angular/cli/package.json (relative path: ./models/webpack-configs)
        using description file: /Users/tyyiu/Documents/Code/IONIC/quorra/package.json (relative path: ./src/main.ts)
          no extension
            Field 'browser' doesn't contain a valid alias configuration
            /Users/tyyiu/Documents/Code/IONIC/quorra/src/main.ts doesn't exist
          .ts
            Field 'browser' doesn't contain a valid alias configuration
            /Users/tyyiu/Documents/Code/IONIC/quorra/src/main.ts.ts doesn't exist
          .js
            Field 'browser' doesn't contain a valid alias configuration
            /Users/tyyiu/Documents/Code/IONIC/quorra/src/main.ts.js doesn't exist
          as directory
            /Users/tyyiu/Documents/Code/IONIC/quorra/src/main.ts doesn't exist
    [/Users/tyyiu/Documents/Code/IONIC/quorra/src/main.ts]
    [/Users/tyyiu/Documents/Code/IONIC/quorra/src/main.ts.ts]
    [/Users/tyyiu/Documents/Code/IONIC/quorra/src/main.ts.js]
    [/Users/tyyiu/Documents/Code/IONIC/quorra/src/main.ts]
     @ multi ./src/main.ts
    ERROR in multi ./src/polyfills.ts
    Module not found: Error: Can't resolve '/Users/tyyiu/Documents/Code/IONIC/quorra/src/polyfills.ts' in '/Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@angu
    lar/cli/models/webpack-configs'
    resolve '/Users/tyyiu/Documents/Code/IONIC/quorra/src/polyfills.ts' in '/Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@angular/cli/models/webpack-configs'
      using description file: /Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@angular/cli/package.json (relative path: ./models/webpack-configs)
        Field 'browser' doesn't contain a valid alias configuration
      after using description file: /Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@angular/cli/package.json (relative path: ./models/webpack-configs)
        using description file: /Users/tyyiu/Documents/Code/IONIC/quorra/package.json (relative path: ./src/polyfills.ts)
          no extension
            Field 'browser' doesn't contain a valid alias configuration
            /Users/tyyiu/Documents/Code/IONIC/quorra/src/polyfills.ts doesn't exist
          .ts
            Field 'browser' doesn't contain a valid alias configuration
            /Users/tyyiu/Documents/Code/IONIC/quorra/src/polyfills.ts.ts doesn't exist
 .ts
        Field 'browser' doesn't contain a valid alias configuration
        /Users/tyyiu/Documents/Code/IONIC/quorra/src/polyfills.ts.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        /Users/tyyiu/Documents/Code/IONIC/quorra/src/polyfills.ts.js doesn't exist
      as directory
        /Users/tyyiu/Documents/Code/IONIC/quorra/src/polyfills.ts doesn't exist
[/Users/tyyiu/Documents/Code/IONIC/quorra/src/polyfills.ts]
[/Users/tyyiu/Documents/Code/IONIC/quorra/src/polyfills.ts.ts]
[/Users/tyyiu/Documents/Code/IONIC/quorra/src/polyfills.ts.js]
[/Users/tyyiu/Documents/Code/IONIC/quorra/src/polyfills.ts]
 @ multi ./src/polyfills.ts

ERROR in multi ./src/styles.css
Module not found: Error: Can't resolve '/Users/tyyiu/Documents/Code/IONIC/quorra/src/styles.css' in '/Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@angula
r/cli/models/webpack-configs'
resolve '/Users/tyyiu/Documents/Code/IONIC/quorra/src/styles.css' in '/Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@angular/cli/models/webpack-configs'
  using description file: /Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@angular/cli/package.json (relative path: ./models/webpack-configs)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: /Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@angular/cli/package.json (relative path: ./models/webpack-configs)
    using description file: /Users/tyyiu/Documents/Code/IONIC/quorra/package.json (relative path: ./src/styles.css)
      no extension
        Field 'browser' doesn't contain a valid alias configuration
        /Users/tyyiu/Documents/Code/IONIC/quorra/src/styles.css doesn't exist
      .ts
        Field 'browser' doesn't contain a valid alias configuration
        /Users/tyyiu/Documents/Code/IONIC/quorra/src/styles.css.ts doesn't exist
      .js
        Field 'browser' doesn't contain a valid alias configuration
        /Users/tyyiu/Documents/Code/IONIC/quorra/src/styles.css.js doesn't exist
      as directory
        /Users/tyyiu/Documents/Code/IONIC/quorra/src/styles.css doesn't exist
[/Users/tyyiu/Documents/Code/IONIC/quorra/src/styles.css]
[/Users/tyyiu/Documents/Code/IONIC/quorra/src/styles.css.ts]
[/Users/tyyiu/Documents/Code/IONIC/quorra/src/styles.css.js]
[/Users/tyyiu/Documents/Code/IONIC/quorra/src/styles.css]
 @ multi ./src/styles.css
ERROR in TypeError: Cannot read property 'length' of undefined
    at createSourceFile (/Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/typescript/lib/typescript.js:16640:109)
    at parseSourceFileWorker (/Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/typescript/lib/typescript.js:16572:26)
    at Object.parseSourceFile (/Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/typescript/lib/typescript.js:16521:26)
    at Object.createSourceFile (/Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/typescript/lib/typescript.js:16371:29)
    at new TypeScriptFileRefactor (/Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@ngtools/webpack/src/refactor.js:79:35)
    at Object.resolveEntryModuleFromMain (/Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@ngtools/webpack/src/entry_resolver.js:108:20)
    at Promise.resolve.then.then (/Users/tyyiu/Documents/Code/IONIC/quorra/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:240:54)

文件树: src/tsconfig.json ; src/app ; src/pages -> 我将 tsconfig.json 放入 src 文件夹,否则会出现错误,提示找不到它。

我想知道错误在哪里以及原因。如果是因为我将 tsconfig.json 放入 src/ 文件夹,那么为什么会出现找不到文件的错误,即使它就在那里?

我的 tsconfig.json 来自: https://github.com/kristofferandreasen/simple-ionic-3-app/blob/master/tsconfig.json

2个回答

首先运行

npm i

然后运行以下命令

ionic cordova build --release android --prod
FatehiAbdoThabit
2017-12-16

这就是您构建 Angular 项目而非 Ionic 项目的方法。方法如下,您可以选择以下命令之一:

$ ionic build
$ ionic cordova build ios
$ ionic cordova build ios --prod --release
$ ionic cordova build ios --device --prod --release -- --developmentTeam="ABCD" --codeSignIdentity="iPhone Developer" --packageType="app-store"
$ ionic cordova build android
$ ionic cordova build android --prod --release -- -- --keystore=filename.keystore --alias=myalias
$ ionic cordova build android --prod --release -- -- --minSdkVersion=21
$ ionic cordova build android --prod --release -- -- --versionCode=55

但据我所知,您可能需要 $ ionic build

Melchia
2017-12-16