【问题标题】:SyntaxError: Unexpected token import while using Nuxt 2.0 build.transpileSyntaxError:使用 Nuxt 2.0 build.transpile 时出现意外的令牌导入
【发布时间】:2019-03-21 04:00:14
【问题描述】:

我正在使用 Nuxt@2 build.transpile 选项 (https://nuxtjs.org/api/configuration-build#transpile):

nuxt.config.js

build: {
  transpile: [
    '@namespace/node-module-name/file.js'
  ]
}

不幸的是,我在构建时仍然收到错误:

✖ error /Users/me/project/node_modules/@namespace/node-module-name/file.js:1
(function (exports, require, module, __filename, __dirname) { import createAPI from '@namespace/api';
 ^^^^^^

 SyntaxError: Unexpected token import

nuxt babel 配置是否能够将imports 替换为 umd、commonjs 等?

【问题讨论】:

  • 你能在codesandbox或github repo上创建一个复制品吗?

标签: vue.js webpack babeljs nuxt.js babel-loader


【解决方案1】:

代替:

import createAPI from '@namespace/api'

请尝试以下方法:

const createAPI = require('@namespace/api')

【讨论】:

    猜你喜欢
    • 2019-04-04
    • 2017-07-17
    • 1970-01-01
    • 2019-08-07
    • 2018-09-24
    • 2018-11-10
    相关资源
    最近更新 更多