在ionic2项目的创建过程中,遇到了不少问题,前前后后花了不少时间才解决。
在网上查到,可能是npm的版本问题,但是也只是可能。所以我就先照着简单的方法做了。比如,直接跳过npm这个步骤。
使用命令行创建ionic项目
ionic start --v2 myApp tabs 我第一次遇到了这样的错误 Installing npm packages... Error with start undefined Error Initializing app: There was an error with the spawned command: npminstall There was an error with the spawned command: npminstall 天知道发生了什么。后来重新创建的时候遇到了更可怕的错误。 Unable to run exec commandError: Command failed: npm install npm WARN prefer global node-gyp@3.5.0 should be installed with -g Cannot download "https://github.com/sass/node-sass/releases/download/v4.5.0/win3 2-x64-48_binding.node": ESOCKETTIMEDOUT Hint: If github.com is not accessible in your location try setting a proxy via HTTP_PROXY, e.g. export HTTP_PROXY=http://example.com:1234 or configure npm proxy via npm config set proxy http://example.com:8080 gyp info it worked if it ends with ok gyp verb cli [ 'C:\\Program Files\\nodejs\\node.exe', gyp verb cli 'G:\\myionicapp\\myApp\\node_modules\\node-gyp\\bin\\node-gyp.js' , gyp verb cli 'rebuild', gyp verb cli '--verbose', ...此处省略几十行 就算我知道某个地方有错,我也不敢保证以我的水平能够handle它。本来我就是个小白。于是在网上搜到有说,“在执行npm后无法访问国外资源库。所以我们的操作是只创建项目不创建依赖”。
执行这样的命令。
ionic start --v2 myApp --skip-npm然后再cd进myApp目录,执行以下命令: cnpm install --save嗯。的确可以执行ionic serve。结果执行ionic serve之后,网页打开显示 Error: ENOENT: no such file or directory, open 'g:\myionicapp\myApp\www\index.html'
WHAT HAPPENED???
后来又在网上搜到,说,这个bug在beta22已经修复,所以感觉是ionic的问题,所以npm stall -g ionic,安装后版本为2.2.1,再start项目,然后ionic serve正常,www文件夹下的文件也全了。 升级之后终于能够正常运行(看起来正常)。
参考资料:http://www.cnblogs.com/momoxiaoqing/p/6226706.html (这个小姐姐的博客写得很详细,包括了ionic1和ionic2 刚开始创建所能遇到的大部分问题,并且解决方法亲测可行)