zoukankan      html  css  js  c++  java
  • ng2

    angularjs2的环境问题解决了好久。

    百度到的答案也是各种各样还解决不了我的问题。

    好在这几天经过不断的测试终于给解决了。

    [html] view plain copy
     
     print?
    1. ERROR in AppModule is not an NgModule  
    2.   
    3.   
    4. ERROR in ./src/main.ts  
    5. Module build failed: TypeError: Cannot read property 'newLine' of undefined  
    6.     at Object.getNewLineCharacter (d:webmyNg g2 ode_modules ypescriptlib ypescript.js:8062:20)  
    7.     at Object.createCompilerHost (d:webmyNg g2 ode_modules ypescriptlib ypescript.js:44978:26)  
    8.     at Object.ngcLoader (d:webmyNg g2 ode_modules@ngtoolswebpacksrcloader.js:338:33)  
    9.  @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts  
    10.   
    11.   
    12. ERROR in ./src/polyfills.ts  
    13. Module build failed: TypeError: Cannot read property 'newLine' of undefined  
    14.     at Object.getNewLineCharacter (d:webmyNg g2 ode_modules ypescriptlib ypescript.js:8062:20)  
    15.     at Object.createCompilerHost (d:webmyNg g2 ode_modules ypescriptlib ypescript.js:44978:26)  
    16.     at Object.ngcLoader (d:webmyNg g2 ode_modules@ngtoolswebpacksrcloader.js:338:33)  
    17.  @ multi ./src/polyfills.ts  
    18. webpack: Failed to compile.  


    出现这个错误的原因是本地typescript版本冲突了。但是我不知道npm为什么会这样。网上说它的机制按理说不是会导致版本冲突的问题。没有研究过。

    首先:

    $ npm ls typescript

    输入这个命令查看项目的typescript版本和依赖。

    发现出现2个不同的版本在各个地方了。

    由于angularcli依赖的是2.1.6,这个是自动生成的,总不能去node_module里面去找package.json改吧。没法改。放弃。
    ng2@0.0.0 d:webmyNg g2
    +-- @angular/cli@1.0.0-rc.1 -> d:webmyNg g2 ode_modules.1.0.0-rc.1@@angularcli
    | +-- @angular/compiler-cli@2.4.9
    | | +-- @angular/tsc-wrapped@0.5.2
    | | | `-- typescript@2.1.6  deduped extraneous
    | | `-- typescript@2.1.6  extraneous
    | +-- @angular/tsc-wrapped@0.5.2
    | | +-- tsickle@0.2.6
    | | | `-- typescript@2.1.6  extraneous
    | | `-- typescript@2.1.6  extraneous
    | +-- @ngtools/webpack@1.2.12
    | | `-- typescript@2.1.6  extraneous
    | `-- typescript@2.1.6
    `-- typescript@2.0.10

    那么另一个2.0.10是在项目的package.json中配置的。这个虽然是angular/cli生成的,但是是在我们自己的项目里面,所以很好改,我们把这里的typescript改成angular/cli自己依赖的那个版本。

    "typescript": "~2.0.0"

    把这个改成

    "typescript": "~2.1.0"

    ~表示npm会自动下载离他最近的一个小版本。比如我的电脑上面就是2.1.6。这样的话,就是angular/cli自己依赖的完全一致了。

    再次

    $ npm ls typescript

    发现,版本一致了。
    ng2@0.0.0 d:webmyNg g2
    +-- @angular/cli@1.0.0-rc.1 -> d:webmyNg g2 ode_modules.1.0.0-rc.1@@angularcli
    | `-- typescript@2.1.6
    `-- typescript@2.1.6  -> d:webmyNg g2 ode_modules.2.1.6@typescript

    $ ng serve
    ** NG Live Development Server is running on http://localhost:4200 **
    Hash: b21dc5aadbb6f2b69213
    Time: 10251ms
    chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 158 kB {4} [initial] [rendered]
    chunk    {1} main.bundle.js, main.bundle.js.map (main) 3.14 kB {3} [initial] [rendered]
    chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 9.84 kB {4} [initial] [rendered]
    chunk    {3} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.6 MB [initial] [rendered]
    chunk    {4} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
    webpack: Compiled successfully.

    搞定。在这里做个笔记,希望能帮到之后遇到的人。毕竟这玩意刚接触太浪费时间了。

    对了,安装环境的时候记得用cnpm install。原生的npm install安装会报错,原因是node-sass被墙了

  • 相关阅读:
    洛谷 [SDOI2015]约数个数和 解题报告
    multiset-count
    multiset-begin
    multiset-begin
    set-value_comp
    set-value_comp
    multiset-constructors
    multiset-constructors
    set-upper_bound
    set-upper_bound
  • 原文地址:https://www.cnblogs.com/jack-lin/p/7059607.html
Copyright © 2011-2022 走看看