SyntaxError:使用Nuxt 2.0 build.transpile时意外的令牌导入

问题描述 投票:0回答:1

我正在使用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配置是否能够用umd,commonjs等替换imports?

vue.js webpack babeljs nuxt.js babel-loader
1个回答
0
投票

代替:

import createAPI from '@namespace/api'

请尝试以下方法:

const createAPI = require('@namespace/api')
© www.soinside.com 2019 - 2024. All rights reserved.