ionic常见报错解决方案&常用命令

常见报错

  • npm WARN checkPermissions Missing write access to
    Solution

    1. 方案一

    2. 方案二

      • sudo npm i -g npm // 重新全局安装npm
      • sudo chown -R your_user_name /usr/local/lib // 修改npm文件夹的权限
  • Downloading and extracting blank starter - failed!Error: socket hang up
    Solution:

  1. 针对特定版本的解决方案:https://www.jianshu.com/p/6509070114e2
  2. sudo cnpm install -g ionic cordova // 需要记住的核心思想:能用cnpm尽量不要用npm
  3. ionic start myApp https://github.com/ionic-team/starters // 如果模板源的网站没有响应,则可以尝试直接去github上clone源代码
  • ERROR] The package.json file seems malformed.
    Solution:

    In to of package.json at the root(base level), add ‘name’ key like "name": "My_App_Name",.
    Also at same base level add "author": "YourName",
    
  • 如果需要安装依赖

    cnpm install –save (安装完一些包之后要记得save,这个步骤十分容易忘记)

  • ➜ ionicdemo ionic serve
    Error: Cannot find module ‘tslint’
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object. (/Users/zzy824/ionicPrijects/ionicdemo/nodemodules/@ionic_app-scripts@3.1.8@@ionic/app-scripts/dist/lint/lint-factory.js:3:16)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

    solution:

    > rm -rf node_modules  
    > npm restart
    > npm update  
    > cnpm install --save  
    
  • npm install出现”Unexpected end of JSON input while parsing near”

npm cache clean –force

  • ionic中调用摄像头

提前准备plugman:一个专门为了cordova提供插件的命令行工具
npm installd -g plugman
第一步是安装ionic-native/core。所有用到Native的功能,这一步不能省。
npm install @ionic-native/core –save

  • “/usr/bin/env: node: No such file or directory”
    软链接文件: ln -s /usr/bin/nodejs /usr/bin/node

常用命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
//下载依赖包
cnpm i
//移动端启动
ionic serve -l

//在一个连接的设备上运行项目
ionic cordova run [platform] [options]
ionic cordova run [ios/android] [-lc]

//在ios手机上运行需要安装平台
ionic cordova platform add ios
ionic cordova platform add android

//在平台下修改代码后打包
ionic build
//在phoneGap上做测试
ionic cordova plugin add phonegap-plugin-local-notification
npm install --save @ionic-native/phonegap-local-notification
//声明一个组件
ionic g component [component name]
//声明一个新页面
ionic g page [page name]

引用与参考

  1. https://blog.csdn.net/yuxiaofan1245023886/article/details/52251410
  2. http://www.jb51.net/article/115645.htm
  3. https://github.com/nodejs/node-v0.x-archive/issues/3911
请zzy824喝杯咖啡
0%