【问题标题】:reexport - SyntaxError: Unexpected token 'export'重新导出 - SyntaxError:意外的令牌“导出”
【发布时间】:2021-07-23 20:59:11
【问题描述】:

有这样一个文件。从 API 导入并立即导出。

export { extractValue, parse, parseCommand }  from './parser'
export { Manager, EVENTS } from './manager'
export { runCLI, runCommand, bootstrapCommandManager } from './cli'

我收到一个错误:

export { extractValue, parse, parseCommand }  from './parser'
^^^^^^

SyntaxError: Unexpected token 'export'

这是我的 babel.config.js

module.exports = {
    presets: [['@babel/preset-env', {targets: {node: 'current'}}]],
    plugins: [
      ['@babel/plugin-transform-modules-commonjs'],
      ['@babel/plugin-proposal-decorators', {'legacy': true}],
      ['@babel/plugin-proposal-class-properties'],
      ['@babel/plugin-proposal-export-default-from']
    ]
  };

@babel/plugin-proposal-export-default-from 没有帮助。

【问题讨论】:

    标签: babeljs


    【解决方案1】:

    它没有从 node_modules 目录编译文件。必须设置忽略规则。 有用 变体 A babel-node

    npx babel-node --ignore="/node_modules\/(?\!console-command-manager)/"  --config-file ./babel.config.js ./src/index.js
    

    我错误地将 --ignore 参数移到 ./babel.config.js

    变体 B 使用 -r runner.js 执行节点 执行

    node -r ./runner.js src/index.js 
    

    跑步者

    const config = require('./babel.config.js')
    console.log(config)
    require("@babel/register")({
      extensions: ['.js'],
      ignore: [
        /node_modules[\\/](?!console-command-manager)/
      ],
      ...config
    });
    

    【讨论】:

      猜你喜欢
      • 2017-07-17
      • 1970-01-01
      • 2021-02-18
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 2021-03-08
      • 2020-09-14
      • 2017-04-06
      相关资源
      最近更新 更多