引入Marked打包时报错class _Tokenizer {...

234 阅读1分钟

使用版本:7.0.0

引入:

yarn add marked@7.0.0
import {marked} from 'marked'

打包时报错:

ERROR in ./node_modules/marked/lib/marked.umd.js 253:15
Module parse failed: Unexpected token (253:15)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|      */
|     class _Tokenizer {
>         options;
|         // TODO: Fix this rules type
|         rules;
 @ ./plugins/markdown.ts 4:13-30
 @ ./.nuxt/index.js
 @ ./.nuxt/client.js
 @ multi ./node_modules/@nuxt/components/lib/installComponents.js ./.nuxt/client.js

解决: 在config.js里面添加

build: {
  transpile: ['marked']
}