最近在做一个基于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,成功运行。