本文介绍了SyntaxError:在 Nuxt 中使用 lodash 时出现意外的令牌导出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的带有现场演示的 repo https://github.com/alechance/nuxt-lodash.我正在使用 Nuxt 和 Vuetify + lodash-es,当运行 npm run dev 并重新加载我的页面时,我得到一个 SyntaxError: Unexpected token exportexport default isArray;

Here is my repo with live demo https://github.com/alechance/nuxt-lodash. I'm using Nuxt with Vuetify + lodash-es, when running npm run dev and reload my page I got a SyntaxError: Unexpected token export with export default isArray;

推荐答案

lodash-es 库的导入文件不会被 babel 转译.为了解决这个问题,Nuxt.js 提供了手动指定文件的选项,这些文件应该通过 transpile 选项.

Imported files of lodash-es library are not transpiled by babel. To fix that, Nuxt.js provides option to manually specify files that should be transpiled via transpile option.

将以下代码添加到nuxt.config.jsbuild部分:

Add following code to build section of nuxt.config.js:

build: {
  transpile: [
    'lodash-es'
  ],
  // Other build options
}

这篇关于SyntaxError:在 Nuxt 中使用 lodash 时出现意外的令牌导出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:53
查看更多