美文网首页
开发时的坑

开发时的坑

作者: Devildi已被占用 | 来源:发表于2018-09-30 22:24 被阅读0次

    Git命令出错

    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    

    问题分析:上述错误为卸载Xcode导致
    解决办法:可以通过如下命令修复xcode-select --install

    Git命令出错

    git push origin master
    To git@github.com:qzmly100/repository-.git
    ! [rejected] master -> master (fetch first)
    error: failed to push some refs to 'git@github.com:qzmly100/repository-.git'
    hint: Updates were rejected because the remote contains work that you do
    hint: not have locally. This is usually caused by another repository pushing
    hint: to the same ref. You may want to first integrate the remote changes
    hint: (e.g., 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    

    问题分析:远程分支上存在本地分支中不存在的提交,往往是多人协作开发过程中遇到的问题
    解决办法:先git pullgit push

    Koa post请求错误

    413 Request Entity Too Large
    

    问题分析:koa-bodyparser中间件对各种POST请求的数据类型的大小做了限制
    解决办法:app.use(bodyParser({formLimit: '1mb'}))

    配置babel使得node可以使用import

    (function (exports, require, module, __filename, __dirname) { import {
                                                                  ^^^^^^
    
    SyntaxError: Unexpected token import
        at createScript (vm.js:80:10)
        at Object.runInThisContext (vm.js:139:10)
        at Module._compile (module.js:607:28)
        at Object.Module._extensions..js (module.js:654:10)
        at Module.load (module.js:556:32)
        at tryModuleLoad (module.js:499:12)
        at Function.Module._load (module.js:491:3)
        at Function.Module.runMain (module.js:684:10)
        at startup (bootstrap_node.js:187:16)
        at bootstrap_node.js:608:3
    

    问题分析:node使用CommonJS模式,胡无法使用import
    解决办法:配置babel
    第一步:

    npm install --save-dev babel-cli babel-preset-es2015
    

    第二步:配置packge.json

     "babel": "babel-node index.js"
    

    第三步:配置.babelrc

    {
      "presets": ["es2015"]
    }
    

    运行npm run babel,完美解决!

    配置babel支持编译ES7新特性

    第一步:

    npm i -D babel-plugin-transform-runtime babel-runtime
    

    第二步:配置编译命令

    "build": "rimraf dist && babel src -s -D -d dist --presets env"
    

    第三步:

    {
      "plugins": ["transform-runtime",{"polifill": false, "regenerator": true}]
    }  
    

    配置babel支持展开运算符

    #安装必要包
    npm i babel-plugin-transform-object-rest-spread --save-dev
    
    #配置.babelrc
    
    {
      "plugins": ["transform-object-rest-spread"]
    }
    

    配置babel支持Decorator

    第一步:

    npm install babel-core babel-plugin-transform-decorators babel-plugin-transform-decorators-legacy -D
    

    第二步:配置.babelrc

    {
      "plugins": ["transform-decorators-legacy"]
    }
    

    相关文章

      网友评论

          本文标题:开发时的坑

          本文链接:https://www.haomeiwen.com/subject/frjgoftx.html