简体   繁体   中英

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

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

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

I solved this problem.

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

./src/parser:

'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);
};

Please add the 'exportDefaultFrom' into plugins.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM