刚安装的Angular Cli会出错而不是运行

时间:2016-10-05 22:12:18

标签: angular npm angular-cli

我一直在尝试安装最新的angular-cli以开始一个新项目,但我遇到了一个非常奇怪的问题。我跑的时候

npm install -g angular-cli@latest

angular-cli似乎安装成功。但是,当我实际尝试使用它或使用

检查版本时
ng --version

我收到此错误:

fs.js:640
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
             ^

TypeError: path must be a string or Buffer
    at TypeError (native)
    at Object.fs.openSync (fs.js:640:18)
    at Object.fs.readFileSync (fs.js:508:33)
    at Function.Version.fromProject (/Users/ryan/.nvm/versions/node/v6.7.0/lib/node_modules/angular-cli/upgrade/version.js:87:31)
    at Function.Version.isPreWebpack (/Users/ryan/.nvm/versions/node/v6.7.0/lib/node_modules/angular-cli/upgrade/version.js:111:31)
    at Function.Version.assertPostWebpackVersion (/Users/ryan/.nvm/versions/node/v6.7.0/lib/node_modules/angular-cli/upgrade/version.js:97:18)
    at /Users/ryan/.nvm/versions/node/v6.7.0/lib/node_modules/angular-cli/bin/ng:25:15
    at /Users/ryan/.nvm/versions/node/v6.7.0/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:44:21
    at ondir (/Users/ryan/.nvm/versions/node/v6.7.0/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:187:31)
    at /Users/ryan/.nvm/versions/node/v6.7.0/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:153:39

我找到了许多类似错误的答案,但他们似乎都暗示问题已在v1.0.0-beta.15中得到解决,而我应该已经安装了v1.0.0-beta.16。无论如何,当我按照最受欢迎的建议我可以找到评论ng(Version.assertPostWebpackVersion();)的第25行时,我只是得到了一个不同的错误:

→ ng --version
module.js:457
    throw err;
    ^

Error: Cannot find module '../models/config'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/ryan/node_modules/angular-cli/packages/angular-cli/addon/index.js:4:16)
    at Module._compile (module.js:556:32)
    at Object.Module._extensions..js (module.js:565:10)
    at Module.load (module.js:473:32)
    at tryModuleLoad (module.js:432:12)
    at Function.Module._load (module.js:424:3)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at Function.Addon.lookup (/Users/ryan/node_modules/ember-cli/lib/models/addon.js:879:19)
    at /Users/ryan/node_modules/ember-cli/lib/models/addons-factory.js:47:36
    at visit (/Users/ryan/node_modules/ember-cli/lib/utilities/DAG.js:23:3)
    at DAG.topsort (/Users/ryan/node_modules/ember-cli/lib/utilities/DAG.js:82:7)
    at AddonsFactory.initializeAddons (/Users/ryan/node_modules/ember-cli/lib/models/addons-factory.js:44:9)
    at Project.initializeAddons (/Users/ryan/node_modules/ember-cli/lib/models/project.js:374:36)
    at Function.Project.nullProject (/Users/ryan/node_modules/ember-cli/lib/models/project.js:131:16)
    at Function.Project.projectOrnullProject (/Users/ryan/node_modules/ember-cli/lib/models/project.js:640:22)
    at module.exports (/Users/ryan/node_modules/ember-cli/lib/cli/index.js:94:25)
    at module.exports (/Users/ryan/node_modules/angular-cli/packages/angular-cli/lib/cli/index.js:45:10)
    at /Users/ryan/.nvm/versions/node/v6.7.0/lib/node_modules/angular-cli/bin/ng:36:5
    at /Users/ryan/.nvm/versions/node/v6.7.0/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:44:21
    at ondir (/Users/ryan/.nvm/versions/node/v6.7.0/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:187:31)
    at /Users/ryan/.nvm/versions/node/v6.7.0/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:153:39
    at onex (/Users/ryan/.nvm/versions/node/v6.7.0/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:93:22)
    at /Users/ryan/.nvm/versions/node/v6.7.0/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:24:18

提前感谢您的帮助。

node:v6.7.0

npm:3.10.3

os:osx El Capitan

编辑:有关我当前设置的其他信息,请参阅回复提交中的评论:

→ npm list -g typescript
/Users/ryan/.nvm/versions/node/v6.7.0/lib
└─┬ angular-cli@1.0.0-beta.16
  ├─┬ @angular-cli/ast-tools@1.0.2
  │ └── typescript@2.0.0
  ├─┬ typedoc@0.4.5
  │ └── typescript@1.8.10
  └── typescript@2.0.2

→ npm list -g webpack
/Users/ryan/.nvm/versions/node/v6.7.0/lib
└─┬ angular-cli@1.0.0-beta.16
  └── webpack@2.1.0-beta.22

→ npm list -g angular-cli
/Users/ryan/.nvm/versions/node/v6.7.0/lib
└── angular-cli@1.0.0-beta.16

2 个答案:

答案 0 :(得分:0)

先决条件

首先,确保您拥有Node 4.x和NPM 3.x。

请注意,Node 4.x(至少高达4.4.2,可能是更新的版本)附带NPM 2.x而非3.x。

因此,如果您有Node 4.x,请运行以下命令将NPM升级到最新版本:

npm i -g npm

(如果需要,请使用get Num from user get IsPrime = True for PFactor ranges from 2 to Num-1 do begin block if Num divisible by PFactor then set IsPrime = False end block if IsPrime = True then display Num is prime else display Num is not prime ; BTW,如图所示运行install,而不是更新)

如果您有节点0.10或0.12,您可能想安装它,并在sudo目录中查找提及节点或npm的任何文件或文件夹并删除它们。那些版本太粘了。

清理安装

现在,假设您拥有所有正确的版本,请运行:

npm rm -g angular-cli
npm cache clear
npm i -g angular-cli

更多疑难解答

如果这不起作用,请重复之前的3行,但将~/添加到安装行,这样就变为:

npm rm -g angular-cli
npm cache clear
npm i -g angular-cli --no-optional

答案 1 :(得分:-1)

尝试在没有 node_modules package.json 的目录中运行ng --version,这会影响结果。

尝试执行以下操作以更新所有全局程序包:

npm update -g

我的OS X设置

> ng --version                                                                                                     
angular-cli: 1.0.0-beta.16                                                                                                                               
node: 6.7.0                                                                                                                                              
os: darwin x64                                                                                                                                           
> node -v                                                                                                          
v6.7.0                                                                                                                                                   
> npm -v                                                                                                           
3.10.8                                                                                                                                                   
> npm list -g typescript                                                                                           
/usr/local/lib                                                                                                                                           
├─┬ angular-cli@1.0.0-beta.16                                                                                                                            
│ ├─┬ @angular-cli/ast-tools@1.0.2                                                                                                                       
│ │ └── typescript@2.0.0                                                                                                                                 
│ ├─┬ typedoc@0.4.5                                                                                                                                      
│ │ └── typescript@1.8.10                                                                                                                                
│ └── typescript@2.0.2                                                                                                                                   
└─┬ typings@1.4.0                                                                                                                                        
  └─┬ typings-core@1.5.0                                                                                                                                 
    └── typescript@2.0.3                                                                                                                                 

> npm list -g webpack                                                                                              
/usr/local/lib                                                                                                                                           
├─┬ angular-cli@1.0.0-beta.16                                                                                                                            
│ └── webpack@2.1.0-beta.22                                                                                                                              
└── webpack@1.13.2                                                                                                                                       

> npm list -g angular-cli                                                                                          
/usr/local/lib                                                                                                                                           
└── angular-cli@1.0.0-beta.16