5

This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom'

我在尝试通过使用 facebook 中的迁移工具将整个应用程序从 react 移动v15.6到时遇到上述错误。v16.2jscodeshift

4

2 回答 2

2

我解决了这个问题。

const parser = require('./src/parser');
const jscodeshift = require('jscodeshift').withParser(parser);

./src/解析器:

'use strict';

const babylon = require('babylon');

// These are the options that were the default of the Babel5 parse function
// see https://github.com/babel/babel/blob/5.x/packages/babel/src/api/node.js#L81

const options = {
  sourceType: 'module',
  allowHashBang: true,
  ecmaVersion: Infinity,
  allowImportExportEverywhere: true,
  allowReturnOutsideFunction: true,
  plugins: [
    'estree',
    'jsx',
    'asyncGenerators',
    'classProperties',
    'doExpressions',
    'exportExtensions',
    'functionBind',
    'functionSent',
    'objectRestSpread',
    'dynamicImport',
    'nullishCoalescingOperator',
    'optionalChaining',
    'exportDefaultFrom'
  ],
};

/**
 * Wrapper to set default options
 */
exports.parse = function parse (code) {
  return babylon.parse(code, options);
};

请将“exportDefaultFrom”添加到插件中。

于 2018-11-13T11:29:11.270 回答
2

将 @babel/plugin-proposal-export-default-from ( https://git.io/vb4yH ) 添加到 Babel 配置的“插件”部分以启用转换。

于 2018-09-10T19:48:29.150 回答