vue init nuxt-community/koa-template nuxt-learn 安装执行npm run dev报错

最近在做一个基于vue的美团全栈项目,技术栈用到nuxt和koa的组合,vue init nuxt-community/koa-template nuxt-learn创建项目之后,执行npm run dev,报错

 ERROR  Failed to compile with 1 errors                                                                         11:27:32

 error  in ./server/index.js

Module build failed: Error: Plugin/Preset files are not allowed to export objects, only functions. In F:\vue\nuxt-learn1\node_modules\backpack-core\babel.js

谷歌一下,说的是babel编译版本有问题,换了关键字:vue init nuxt/koa babel版本问题,找到一篇能完美解决问题的博文:https://www.cnblogs.com/ITtt/p/10515456.html

 解决办法是升级backpack-core@0.3.0到backpack-core@0.7.0

 npm install backpack-core@0.7.0 --save-dev

 再执行npm run dev,编译能成功,但是客户端运行报错

 DONE  Compiled successfully in 384ms                                                                           11:46:44

i Preparing project for development                                                                           11:46:46
i Initial build may take a while                                                                              11:46:46
√ Builder initialized                                                                                         11:46:46
√ Nuxt files generated                                                                                        11:46:46

× Client
  Compiled with some errors in 1.69s

* Server █████████████████████████ building (18%) 74/75 modules 1 active
 url-loader » assets\img\logo.png


 ERROR  Failed to compile with 1 errors                                                       friendly-errors 11:46:49

Module build failed (from ./node_modules/eslint-loader/index.js):                             friendly-errors 11:46:49
TypeError: Cannot read property 'eslint' of undefined
    at Object.module.exports (F:\vue\nuxt-learn1\node_modules\eslint-loader\index.js:148:18)
                                                                                              friendly-errors 11:46:49
You may use special comments to disable some warnings.                                        friendly-errors 11:46:49
Use // eslint-disable-next-line to ignore the next line.                                      friendly-errors 11:46:49
Use /* eslint-disable */ to ignore all warnings in a file.                                    friendly-errors 11:46:49


× Client
  Compiled with some errors in 1.69s

√ Server
  Compiled successfully in 2.01s

解决办法:

nuxt.config.js里找到eslint-loader将ctx.isClient改成ctx.Client就可以运行了。

 extend (config, ctx) {
      if (ctx.Client) {
        config.module.rules.push({
          enforce: 'pre',
          test: /\.(js|vue)$/,
          loader: 'eslint-loader',
          exclude: /(node_modules)/
        })
      }
    }

参考链接:https://www.blyoo.com/3260.html,给出的解释如下:

最后,修改完成执行npm run dev,成功运行。

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值